2008/9/11 Timo Rantalaiho <[EMAIL PROTECTED]> Hi Timo, thanks for your reply. See below for comments.
On Wed, 10 Sep 2008, Jan Stette wrote: > > I've had a few problems with WicketTester recently and would like to > submit > > a request for when it gets overhauled for version 1.5 (is that still the > > plan by the way?): > > Depending on what exactly "overhaul" means (English is not > my native language), yes it is :) Cool! > > It would be really useful to have a clean way to hook in code to execute > > pre- and post-request for operations that take place through > WicketTester. > > In other words, some way to intercept all operations. In a real > > application, I can use a ServletFilter or override methods in > WicketFilter > > to perform per-request initialisation and cleanup, but WicketTester > doesn't > > execute its operations through these classes. So it would be very useful > to > > do something similar when using WicketTester. > > I'm not sure I understand what are you trying to achieve. Do > you have a concrete example? One example is where something like a Hibernate Session is initialised and a transaction created at the start of each request, then closed at the end of the request. So, to make the same steps happen in a test that uses the WicketTester. > WicketTester (and unit testing in general) should aim to > test one behavior of an object in a certain state per test > execution. So the test methods should conceptually be > something like > > Panel containing selected user > - is visible > - displays user data > - stores changed user data > > It sounds suspicious if you do a lot of operations in a single > unit test method. Longer integration / acceptance / functional > tests are better done with a different kind of tool that is > actually invoking the whole deployed application. > > Does this seem to make sense? Absolutely, I see what you're saying. Part of the problem here may be that on the project I'm working on, WicketTester is indeed used to do integration/functional tests. I'm not sure why this was done in the first place, but it does seem to work - most of the time! I guess the API that WicketTester provides for performing actions like clicking links, submitting forms etc. was convenient to drive from the system test harness, possibly simpler than actually driving a "real" web front end. Anyway, if this really is an abuse of WicketTester that you have no intention of supporting, then please say so! > I've tried various ways for doing this. One was to extend the > RequestCycle > > with code that it calls out to "pre" processing when created and "post" > > processing when detached. I found this didn't work as sometimes > > WicketTester will create multiple request cycles whilst performing a > single > > operation, so I got multiple invocations to the "pre" code. > > Do you have an example of when multiple request cycles get > created on a single operation? It sounds strange. Maybe the > request cycle gets created ad hoc (as you mentioned) in some > places without checking first whether there is one in place > already. Looking closer at this to find an example, I've realised that it's our own extended WicketTester class that does this in a lot of cases, for reasons that aren't entirely clear to me. So it's probably our fault - sorry about that. (The guy who wrote this code is no longer with us so I'm trying to piece all this together...) Still, there seems to be one case where this happens with just the basic WicketTester functionality. First, creating a WicketTester: XWicketTester.createRequestCycle() line: 436 XWicketTester(MockWebApplication).<init>(WebApplication, String) line: 199 XWicketTester(BaseWicketTester).<init>(WebApplication, String) line: 205 XWicketTester(WicketTester).<init>(WebApplication, String) line: 308 XWicketTester(WicketTester).<init>(WebApplication) line: 291 XWicketTester.<init>(WebApplication) line: 65 Test(Test).initTester() line: 141 Test(Test).openLoginPage() line: 197 then directly afterwards going to a page: XWicketTester.createRequestCycle() line: 436 XWicketTester(MockWebApplication).setupRequestAndResponse(boolean) line: 547 XWicketTester(MockWebApplication).setupRequestAndResponse() line: 561 XWicketTester(MockWebApplication).processRequestCycle(Class, PageParameters) line: 370 XWicketTester(MockWebApplication).processRequestCycle(Class) line: 359 XWicketTester(BaseWicketTester).startPage(Class) line: 290 Test(Test).openLoginPage() line: 197 I can't see any call to RequestCycle.detach() between those two. Hope that makes sense at all... Regards, Jan