struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: unit testing Struts2 application (with Spring and Hibernate)
Date Fri, 17 Jul 2009 09:32:58 GMT
JWebUnit integrates? nicely with eclipse. I fall in the?'unit tests are for small? units' group.
If your validation is configured wrong you won't fix it in the action so you are not really
testing the action at that point. I prefer separate JUnit unit tests and JWebUnit tests to
the whole enchilada.

-----Original Message-----
From: Wes Wannemacher <>
To: Struts Users Mailing List <>
Sent: Fri, Jul 17, 2009 10:59 am
Subject: Re: unit testing Struts2 application (with Spring and Hibernate)

On Thursday 16 July 2009 07:14:30 pm Dave Newton wrote:
> IMO that's outside the purview of unit testing, though--by definition
> this describes integration testing: the testing of an action along with
> the framework.
> There's nothing *wrong* with doing that testing, I just don't think it's
> the same thing as unit testing: independently testing the smallest bits
> of functionality.
> JUnit can be used for that kind of testing too (and I do, sometimes),
> but once I'm at that point I generally figure I might as well just be
> doing client-focused testing and testing the output of my results. I
> also use Selenium, although I may switch back to using a layer I wrote
> on top of Watir.
> Dave

Not to throw weight around, but it is sort of curious to me that the three 
struts committers who chimed in all agreed that tip-to-tail integration 
testing in JUnit is not worth the effort. I only bring it up because, IMO, 
struts 2 is one of the best-unit-tested products I've ever worked on. I think 
Dave, Musachy and myself are biased against tip-to-tail in JUnit because in 
Struts 2, we have a guideline to unit test all bugfixes and new functionality. 
That being so, all three of us have probably come across situations where 
writing the unit test is 500x harder than writing the fix :)

Dave does a good job of making the point I tried to make earlier, tip-to-tail 
testing is better looked at as an integration test and it becomes much easier 
to deal with as an integration test. If you are unfamiliar with selenium, it 
is worth learning. One of the posters earlier mentioned that he didn't want to 
learn another testing framework when he already knows JUnit. Selenium is nice 
because it runs right in the browser (IE and Firefox) and runs though a set of 
VB-like instructions... Things like - open this url, look for this text, click 
this link and then make sure this text exists. IMO, if you want to make sure 
that your action renders the appropriate result, this is way better than 
trying to coax the framework 
by bootstrapping it with mocks then figuring out a 
way to retrieve the rendered result. As an added bonus, it is possible to get 
maven to launch selenium tests, so you can get full unit and integration 
testing out of your CI if you are willing to put forth the effort.

To drive the point home further, I would add that the Dojo plugin probably 
would have been more stable if we had taken the selenium approach (that is 
being employed with the slowly moving jquery plugin). 


Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more

To unsubscribe, e-mail:
For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message