I am Paul Wilson; Mere Complexities Limited, sells my consulting, coaching, and coding services. I am passionate about Agile, particularly Test Driven Development.


Do I need to test that?

You only need to test the stuff that you want to work. Kent Beck.

So do you need to test this?

        public String getNonsense()
        {
            return nonsense;
        }

The TDD Prime Directive is every new piece of production code must be written against a failing test. So if you need it, you first need to write a failing test that demonstrates why you need it. If you don’t need it, don’t write it.

If the code needs a trivial test, write it. If you skip writing a test for a good reason, then you’ll end up skipping one for a bad reason. When others see you skipping a test, then you are sending a message that it’s okay to make that kind of call: you’re lowering the ethos of the whole team.

On the other hand many trivial tests are a code smell. It can indicate that you’re testing at the wrong level. Rather than testing a getter, this might be the test you need:

       clownDataStub.add(clown(23).withNonsense("wibble").withShoes("large"));
       Clown clown = clownRepository.getClown(23);
       assertEquals("wibble", clown.getNonsense());
       assertEquals("large", clown.getShoes());

0 Comments:

Post a Comment

<< Home

subscribe here subscribe

About me

picture

Conference

RailsConf Europe 2008
Scotland on Rails Organiser

Previous blog posts

Blog archive

Other links: