Today we added our first page unit test using tapestry. Tapestry offer some nice mechanisms to easily test the rendered pages (see the tutorial); however some steps can be a bit tricky (essentially if you want to use the gaedopersistence layer in your tests) so I’ll give a few hints here.
Tapestry provides a PageTester object that takes care about injection registry loading and page rendering.
The PageTester takes an app package name and app name as parameters in its constructor. Make sure you don’t make a mistake in them, because you won’t get any error even if the package or app module don’t exist, so check it twice if your test is failing without evident reason.
To use the gaedo module, load it by adding it to the PageTester constructor. Moreover some configuration is required to work with a local database environment. All those steps can be done in an extension of the PageTester:
Last point: in the tapestry documentation you’ll see that you must use the invoke method of the PageTester with a ComponentInvocation instance to provide a context to a given page. But if you use this, you’ll get a compilation error, since the invoke method doesn’t seem to exist yet/anymore (?). As explained in this thread, you can use the url passed to the render method to set the context. In the second test you can see we pass “John” as context to the “People” page by requesting the “People/John”. Easy, isn’t it? Happy testing with gaedo and tapestry!