Tapestry 页面 junit 测试

Tapestry page junit test

我尝试为 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.

但这是我的网络应用程序中的一个工作页面,它呈现得很好。

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

提前致谢!

一般来说,只有当您为页面的包通知错误 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>