KT has written about JUnit, Test your behavior not methods.
I definitely feel this one. It seems that there is a flow of cause and effects that we run into in our world:
- Someone comes up with a good idea
- The idea is spread
- The idea gets tweaked along the way
- Mass adopters follow the letter of the warped idea, and not the thought behind it
When I look at that flow, I could be talking about a lot of things. For example, Religion :)
Where does this fit into unit testing?
Well, the idea of doing unit tests is obviously a good one. Test Driven Development is also a great tool that we can use to get good designs, and less bugs.
However, it has somehow been warped in many dev shops. In these shops they take the LETTER of the idea “build unit tests == good” and focus on making as many unit tests as possible. Their code coverage tool helps make a game out of this. “I have got 80% coverage”.
However, who gives a monkeys about your coverage compared to the QUALITY of your damn tests. It is easy to use a tool, or manually, create tests for every method and branch, but most of the tests are crap!
I would rather have less coverage (and at areas where I think I really need them) which have really smart tests of behaviour (not just passing nulls and seeing what happens).
September 16th, 2004 at 4:56 pm
Can’t… resist… the plug…
I think both methods and behaviors need to be tested.
Groups in TestNG help achieve that. You are free to create as many test methods as you want, and after that, you put them in a group which you can invoke separately.
http://beust.com/testng
–
Ced