[英]Tapestry page junit test
我嘗試為掛毯 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中的工作頁面,並且呈現效果很好。
有人知道測試有什么問題嗎,或者有人可以向我展示類似的工作測試代碼?
提前致謝!
一般來說,只有在您為頁面的軟件包通知了錯誤的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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.