java - Tapestry页面junit测试

标签 java junit junit4 tapestry

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

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,它表示 请求未处理:“登录”可能不是有效的页面名称。

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

有人知道测试有什么问题吗?或者有人可以向我展示类似的工作测试代码吗?

提前致谢!

最佳答案

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

关于java - Tapestry页面junit测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42856240/

相关文章:

java - Spring 启动 JSP 404

java - 如何用 JSON 字符串中的实际值替换大括号?

java - Junit:测试方法中的 If 子句

java - 单一方法的 JUnit 测试清理

java - 为单元测试添加 protected 方法的良好做法?

java - Sonarqube 测试用例规则不考虑 @Test 注释

java - 流式传输视频并在其上绘制多边形 Java

java - 最长递增子序列。错误在哪里?

cxf - 无法加载扩展类 org.apache.cxf.ws.policy.AssertionBuilderRegistryImpl

java - 在Eclipse 导出的jar 的根目录中查找文件以进行JUNIT 测试