“Programming Ruby” 2nd Edition Update Sam Pullara moves on from BEA
Sep 16

RE: JUnit, Test your behavior not methods

Tech Add comments

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:

  1. Someone comes up with a good idea
  2. The idea is spread
  3. The idea gets tweaked along the way
  4. 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).

One Response to “RE: JUnit, Test your behavior not methods”

  1. Cedric Says:

    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

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What are the first four letters in the word British?