You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by JCoder <in...@jcoder.de> on 2012/08/13 16:18:45 UTC

Basic JUnit Test

Hi all,

Im working at a basic Unit Test that looks like this:

1. tester.assertRenderedPage(FirstPage.class);
2. FormTester formTester = tester.newFormTester("myForm");
3. formTester.submit("myButton");
4. tester.assertRenderedPage(SecondPage.class);

All lines work as expected. Only line 4 fails. I just want to verify a click on a button and after that a certain Page (SecondPage) should be rendered.

The test fails with: "junit.framework.AssertionFailedError: expected:<SecondPage> but was:<FirstPage>"
What did I wrong?

Cheers & Thanks in advance,
Y 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Basic JUnit Test

Posted by Paul Bors <pa...@bors.ws>.
Also get familiar with the API for the WicketTester that extends BaseWicketTester.

There are quite a few useful methods that can aid you during unit testing such as BaseWicketTester#debugComponentTrees() which will output the wicket component tree.

In our unit tests we extended from WicketTester and added a dumpPage() method that would give you both the output of BaseWicketTester#debugComponentTrees() and that of BaseWicketTester#getLastResponseAsString() so a developer can see both the Wicket component tree and the HTML or whatever the last response was (Ajax, etc).

When I write unit tests I use those two methods extensively as I would need to know both the component path in the tree and the expected output or the last response.

There are plenty of other helper methods there as well.

~ Thank you,
  Paul Bors

-----Original Message-----
From: Martin Grigorov [mailto:mgrigorov@apache.org] 
Sent: Monday, August 13, 2012 11:53 AM
To: users@wicket.apache.org
Subject: Re: Basic JUnit Test

Hi,

Put a breakpoint in the button's onSubmit() method and see whether it is actually called.
It could be that you need to call formTester.submit("myForm:myButton");

On Mon, Aug 13, 2012 at 5:18 PM, JCoder <in...@jcoder.de> wrote:
> Hi all,
>
> Im working at a basic Unit Test that looks like this:
>
> 1. tester.assertRenderedPage(FirstPage.class);
> 2. FormTester formTester = tester.newFormTester("myForm"); 3. 
> formTester.submit("myButton"); 4. 
> tester.assertRenderedPage(SecondPage.class);
>
> All lines work as expected. Only line 4 fails. I just want to verify a click on a button and after that a certain Page (SecondPage) should be rendered.
>
> The test fails with: "junit.framework.AssertionFailedError: expected:<SecondPage> but was:<FirstPage>"
> What did I wrong?
>
> Cheers & Thanks in advance,
> Y
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Basic JUnit Test

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Put a breakpoint in the button's onSubmit() method and see whether it
is actually called.
It could be that you need to call formTester.submit("myForm:myButton");

On Mon, Aug 13, 2012 at 5:18 PM, JCoder <in...@jcoder.de> wrote:
> Hi all,
>
> Im working at a basic Unit Test that looks like this:
>
> 1. tester.assertRenderedPage(FirstPage.class);
> 2. FormTester formTester = tester.newFormTester("myForm");
> 3. formTester.submit("myButton");
> 4. tester.assertRenderedPage(SecondPage.class);
>
> All lines work as expected. Only line 4 fails. I just want to verify a click on a button and after that a certain Page (SecondPage) should be rendered.
>
> The test fails with: "junit.framework.AssertionFailedError: expected:<SecondPage> but was:<FirstPage>"
> What did I wrong?
>
> Cheers & Thanks in advance,
> Y
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org