Reputation: 3778
I'm starting out with Wicket, and am doing TDD (using WicketTester
of course).
I came across a problem when trying to create a common layout using markup inheritance.
I looked at online examples including this one. However, those examples don't mention how to test the parent class.
The problem is that the parent class is abstract. This means that WicketTester
cannot instantiate the page and it throws an exception (and rightfully so).
I thought about testing the class as a regular POJO using a mock or a fake class, but then I'll lose the ability to test the wicket components that are in that abstract parent.
Another solution I considered (until I saw the API ...) was to provide a custom IPageProvider
, which will instantiate a fake class/mock instead of throwing an exception. However, the API doesn't seem like something that should be implemented just for one unit test.
In the meantime, I've created the parent class as a concrete class, and I test it with WicketTester
like any other page class. However, the examples demonstrate markup inheritance specifically with an abstract class for the parent page, and it seems that, design-wise, this is the correct thing to do.
Any advice ?
Upvotes: 3
Views: 325
Reputation: 20069
You can just create an anonymous subclass instance during testing.
WicketTester w = new WicketTester();
w.startPage( new AbstractPage() {} );
And you should of course implement all the necessary abstract methods. Also, the AbstractPage
should have it's own html (good practice).
Upvotes: 4
Reputation: 41137
You should be able to just make a test subclass of your abstract parent class and test that using WicketTester
.
I've done that in similar situations and had no problem verifying the rendering and interaction of components of the abstract parent class.
Upvotes: 1