Marc Esher on Designing for Testability
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?





There are no comments for this entry.
[Add Comment]