In the NerdDinner project, there’s this amazing test (see the bottom, second one).
There are so many things wrong here:
- What is exactly correct about these properties?
- Many magic values
- Multiple tests in a single test
- if it fails, its hard to find out why
Here’s how I would approach this kind of validation logic:
use Extract and override, with the test setting the flags for all ‘other’ validation functions except the one I’m testing right now. and I’d at least have two tests for each validation logic. This can also be accomplished with multiple classes and an interface, but I find the tests this way are more readable.