If it isn't worth testing, it isn't worth coding . . .
I won't necessarily disagree that there is some code that is too simple to be worthy of writing tests for. However, I will argue that you should almost never be writing such code . . .
I won't necessarily disagree that there is some code that is too simple to be worthy of writing tests for. However, I will argue that you should almost never be writing such code . . .
Dan North has posted an interesting article suggesting that maybe there are times where a little less DRY (in your test cases) makes for a little more readable. Check out the comments and associated links as well.
What do you think? Input appreciated!
I paired with Ben last night and thoroughly enjoyed the process. It makes it much easier to stick with the TDD when pairing and one of my goals this year is to pair with a number of good programmers as I think you can learn a great deal by watching how other people approach projects.
Anyway, check out the announcement and sign up for the fun!
Even worse examples are methods that call (for instance) now() and then perform a calculation on it. If you do so, you end up with a method you can't test for edge conditions around midnight unless you stay up all night. Tests should be repeatable. If they depend on the state of an external resource (system.time, file system, db, etc) you better have a system of fixtures for putting them into a known state or expect a world of hurt.
In other news, I've been asked for some postings on testing queries. I'll try to get that far in the LightBase rewrite within the week so I can show some strategies for testing both specific sql queries and a generic db abstraction layer (my in-house ORM) using a combination of a simple dbUnit style port, mocking and some other ideas.
In the meantime, check out Marc's post. Anyone else got similar examples of problems they've run into when trying to write tests after the fact?