0

改札アプリケーションで、ホームページ(HomePage.java)が正しくレンダリングされるかどうかを確認したいと思います。

テストケースを書きました

public class TestMerchantProductPage extends TestCase {
private WicketTester tester = null;

@BeforeClass
public void testSetUp(){
    tester = new WicketTester();
    tester.startPage(HomePage.class);
}

@SuppressWarnings("deprecation" )
@Test
public void testPage(){
    tester.assertRenderedPage(HomePage.class);
    tester.startPanel(ItemOrderPanelBySearch.class);

}
}

このようなエラーが発生します

org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor 'public com.zipgrocery.pages.HomePage(org.apache.wicket.request.mapper.parameter.PageParameters)' and argument ''. Might be it doesn't exist, may be it is not visible (public).
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:196)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:77)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:47)
at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:103)
at org.apache.wicket.request.handler.PageProvider.resolvePageInstance(PageProvider.java:264)
at org.apache.wicket.request.handler.PageProvider.getPageInstance(PageProvider.java:165)
at org.apache.wicket.util.tester.BaseWicketTester$LastPageRecordingPageRendererProvider.get(BaseWicketTester.java:2682)
at org.apache.wicket.util.tester.BaseWicketTester$LastPageRecordingPageRendererProvider.get(BaseWicketTester.java:2669)
at org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:166)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:784)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283)
at org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:645)
at org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:565)
at org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:537)
at org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:1209)
at org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:1182)
at com.zipgrocery.TestMerchantProductPage.testSetUp(TestMerchantProductPage.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:173)
... 38 more
Caused by: java.lang.ClassCastException: org.apache.wicket.protocol.http.WebSession cannot be cast to com.zipgrocery.ZipSession
at com.zipgrocery.ZipSession.get(ZipSession.java:45)
at com.zipgrocery.pages.HomePage.<init>(HomePage.java:65)
... 43 more

HomePage.javaにデフォルトのコンストラクターがありません。では、テストケースをどのように書くべきですか?

任意の助けや提案をいただければ幸いです。前もって感謝します !

4

2 に答える 2

1

Wicket 1.5以降は、パラメーターを使用してコンストラクターを呼び出す必要があるため、この場合は

WicketTester tester = new WicketTester(YourApplication);
tester.startPage(new HomePage(YourParameter));
tester.assertRenderedPage(HomePage.class);
于 2012-12-24T10:20:48.140 に答える
1

たぶん、この古いスレッドの解決策はまだ有効です:http: //apache-wicket.1842946.n4.nabble.com/Passing-parameters-to-a-page-in-WicketTester-td1933884.html

于 2012-12-24T20:17:30.913 に答える