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