Почему мой модульный тест выдает ошибку AssertionFailedError, когда я пытаюсь отобразить другую страницу - PullRequest
0 голосов
/ 06 марта 2020

Я изучаю юнит-тестирование и пытаюсь проверить, действителен ли логин на HomePage и, если да, то SuccessPage отображается, но дает мне AssertionFailedError

. java:


    @Test
    public void validLogin(){
        tester.startPage(HomePage.class);

        FormTester form = tester.newFormTester("userForm");
        form.setValue("username", "emile");
        form.setValue("password", "123");
        form.submit();
        //onsubmit the Successpage is rendered in response
        tester.assertRenderedPage(SuccessPage.class);

    }

ошибка:

[main] INFO org.apache.wicket.Application - [WicketTesterApplication-768a67f4-8bf1-45d0-bdcb-3a9be18172e1] init: Wicket core library initializer
[main] INFO org.apache.wicket.Application - [WicketTesterApplication-768a67f4-8bf1-45d0-bdcb-3a9be18172e1] init: Wicket extensions initializer
[main] INFO org.apache.wicket.Application - [WicketTesterApplication-768a67f4-8bf1-45d0-bdcb-3a9be18172e1] init: Wicket jQuery UI initializer
[main] INFO org.apache.wicket.Application - [WicketTesterApplication-768a67f4-8bf1-45d0-bdcb-3a9be18172e1] init: Wicket jQuery UI initializer (theme-uilightness)
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

junit.framework.AssertionFailedError: classes not the same, expected 'class com.mycompany.SuccessPage', current 'class com.mycompany.HomePage'

    at org.apache.wicket.util.tester.WicketTester.assertResult(WicketTester.java:798)
    at org.apache.wicket.util.tester.WicketTester.assertRenderedPage(WicketTester.java:697)
    at com.mycompany.TestHomePage.validLogin(TestHomePage.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

1 Ответ

0 голосов
/ 06 марта 2020

Я получил ответ, поэтому я не ссылался на form.submit(); на функцию onSubmit(), поэтому я в основном сделал это:

@Test
    public void validLogin() throws Exception {
        tester.startPage(HomePage.class);

    //  tester.startComponentInPage(HomePage.class);
        FormTester form = tester.newFormTester("userForm");
        form.setValue("username", "emile");
        form.setValue("password", "123");
        form.submit("error"); // new code that was edited
        //onsubmit the Successpage is rendered in response
        tester.assertRenderedPage(SuccessPage.class);


    }

form.submit("error"); теперь ссылается на wicket:id="error" и прошел тест: D

...