Tapestry页面junit测试

时间:2017-03-17 11:22:56

标签: java junit junit4 tapestry

我尝试为tapestry 5.4页面渲染编写junit测试:

import org.apache.tapestry5.test.PageTester;

public class LoadTest {
    private final String PAGE_NAME = "Login";
    private final String APP_NAME = "";
    private final String context = "src/main/webapp";
    private PageTester tester;

    @Before
    public void init() {
        String appPackage = "hu.webapp";
        tester = new PageTester(appPackage, APP_NAME, context, AppModule.class);
    }

    @Test
    public void confirmIndexIsLoaded() {
        Document document = new Document();
        document = tester.renderPage(PAGE_NAME);
        assertNotNull(document);
    }
}

但我得到RuntimeException,并说Request was not handled: 'Login' may not be a valid page name.

但这是我的webapp中的一个工作页面,它呈现得很好。

有人知道测试有什么问题,或者有人能给我看一个类似的工作测试代码吗?

提前致谢!

1 个答案:

答案 0 :(得分:1)

一般来说,只有当您通知错误的package页面包时,才会发生这种情况。看一下(它对我有用):

import org.apache.tapestry5.test.PageTester;

public class LoadTest {
    private final String PAGE_NAME = "Login"; // It has to be right too!
    private final String APP_NAME = "app"; // Where was your app name?
    private final String context = "src/main/webapp"; // Is that path right in your project?
    private PageTester tester;

    @Before
    public void init() {
        String appPackage = "hu.webapp"; // Check if that's really correct!!!
        tester = new PageTester(appPackage, APP_NAME, context);
    }

    @Test
    public void confirmIndexIsLoaded() {
        Document document = tester.renderPage(PAGE_NAME);
        assertNotNull(document);
    }
}

另外,请检查您的app名称,它应该在您的web.xml中配置为Tapestry过滤器,例如:

<filter>
    <filter-name>app</filter-name>
    <filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>app</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>