使用wicketframework可以使用wickettester並查看lastrenderedpage。 我想測試我的wicketapplication是否將用戶重定向到我的自定義ErrorPage runtimeexceptions和缺少資源(404)。Wicket(Java):如何使用wickettester來測試404是否重定向到正確頁面
對於第一種情況,我將重定向設置爲我的自定義錯誤頁面,並驗證它的工作原理。基本上, 「settings.setInternalErrorPage(ErrorPage.class);
」 並且具有單元測試,基本上雲:
tester = new WicketTester(webApplication);
APage aPage = new APage();
tester.startPage(aPage);
tester.assertRenderedPage(APage.class);
tester.setExposeExceptions(false);
//Page rendered ok, now throw an exception at a button submit
when(aPage.getServiceFacade()).thenThrow(new RuntimeException("DummyException"));
tester.submitForm("searchPanel:searchForm");
tester.assertRenderedPage(ErrorPage.class);//YES, we got redirected to deploymode
所以測試runtimeexecptions - >的errorPage工作正常。 現在來測試缺少的資源。 基本上我在測試時建立的web.xml與「
<error-page>
<error-code>404</error-code>
<location>/error404</location>
</error-page>
,然後我也裝在檢票口。 這工作正常實際使用。但是...我想這..
MockHttpServletRequest request = tester.getRequest();
String contextPath = request.getContextPath();
String filterPrefix = request.getFilterPrefix();
tester.setExposeExceptions(false);
tester.executeUrl(contextPath + "/" + filterPrefix + "/"+ "startpage" + "/MyStrangeurlToNothing);
tester.assertRenderedPage(ErrorPage.class);
但是,測試者對象上的lastrenderedpage在這種情況下不起作用,並且給我null。我想WicketTester不會讀取web.xml文件,所以不知道如何映射這個錯誤。要測試這個嗎?
嗨你有沒有得到任何與此有關的最終?我有同樣的問題 – 2014-01-31 09:22:38