(True I guess I'm writing more of an integration test than a unit test but still . . . .)
Frankly the situation is unacceptable and the developer should be embarrassed. Pretty much everything can be unit tested - it may take a lot of work in some circumstances, but it's doable. True for me, I could write a mock object but that's so much bloody extra work :-)
In the end I figured out a pretty easy way to Unit test both features (and, surprise, surprise, it wasn't that hard). What was *not* surprising for me was that the lack of unit testing in those features was somehow strangely correlated with a significant number of bugs also in those features - funny that! ;-)
Bugs that would have been found with - you guessed it - some simple unit tests!
Being unable to test a feature is a "bad smell" - things like testing database driven apps are hard, yes, but far from impossible and any time invested in helping developers unit test (e.g. mock objects or test database load / unload scripts) is very well worth it IMO.
For those looking beyond just plain old JUnit - I strongly recommend folks take a good look at extensions such as
- HttpUnit for unit testing web interfaces
- DbUnit for a ton of great services to help test database driven apps
- Cactus for container testing
- MockEJB for Mocking EJBs (kind of obvious eh?)
- EasyMock for plain old Mock objects
for nice integration with Eclipse I recommend EclEmma to give you code coverage reports to go with your unit tests (it is surprisingly well featured despite being only at version 0.1.8 at the moment) .
5 comments:
Any tips for unit testing Swing UIs?
Great post! I find that JWebUnit is even more helpful than HttpUnit too.
Great question about Swing UIs - can you really unit test a Swing UI? I mean any UI you see is pretty much "integrated" - so I'm not sure - perhaps you could write unit tests that access the "event listeners".
That said - what a great idea for a (preferably free) product from Sun - something (written in Java?) that can record and playback sequences of clicks against a Swing UI.
I think it would help drive some more increased interest in Swing.
On a related question - how is Eclipse's UI tested?
-Frank
On JWebUnit I've heard some very positive feedback from others - haven't really had the opportunity to use it as I have had with HttpUnit.
-F
Andrew Law said... Any tips for unit testing Swing UIs?
Yes, you can write Swing UIs test first. Try JfcUnit (http://jfcunit.sourceforge.net/). The unfortunate thing is that the tests are a little slow, as some of the Swing components finish their initialization in the display() method.
Post a Comment