You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Niranjan Rao <nh...@gmail.com> on 2011/07/19 01:04:49 UTC
Unit testing wicket
Hi there,
Followed instructions to get wicket working with Spring dependency
injections. It does work in most of the scenarios.
One scenario that is troubling me is unit testing. I have following
simple class. So long as I have one unit test in the class, it works
fine. If I add more than one test case, setUp method is called more than
twice and wicket throws the exception "Application name can only be set
once.". I tried converting setUp to static and using BeforeClass
annotation so that it's initialized only once. This fails as theApp
dependency is not filled by spring.
Any ideas/help will be greatly appreciated.
public class TesterMe {
protected WicketTester tester;
@Autowired
protected WicketApplication theApp;
@Autowired
protected AnnotationSessionFactoryBean sessionFactory;
@Before
public void setUp() {
Assert.assertNotNull("Could not get application", theApp);
tester = new WicketTester(theApp);
}
@Test
public void testSomething()
{
}
}
Regards,
Niranjan
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Unit testing wicket
Posted by Viktoras <it...@gmail.com>.
On 2011.07.19 02:04, Niranjan Rao wrote:
> @Before
> public void setUp() {
> Assert.assertNotNull("Could not get application", theApp);
> tester = new WicketTester(theApp);
>
> }
>
You need a fresh application instance everytime. In our application for
normal execution, app bean is still defined and used through
SpringWebApplicationFactory, but in unit tests, we setup tester like this:
tester = new WicketTester(new App(){
{
this.setApplicationContext(ctx);
}
@Override
protected void outputDevelopmentModeWarning() {
// just get rid of default wicket development message here.
}
});
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org