Testing - Pt 3 - Writing Tests
Tests should be fast to run and fast to write:
- Writing tests should not require time-consuming set-up of databases, DLLs or environments, automate anything of this nature.
- You should not require tacit knowledge of customised systems, no ones want to indulge in tedious manual set up. It's just cost.
- Ask yourself - is running someone else's tests should be possible with a single button?
- The tests themselves should not take long to write.
Don't confuse tests for production code:
- Don't worry too much about writing the most "effective Java" test code, or reuse. Fields don't need to be "private final".
- You don't need to enforce you coding standards on tests.
Test the behaviour, not the method (@Test void testMethodX anyone?):
- Consider a BDD based system.
Consider writing test for interfaces, and then using a parameterized runner that will run the same set of tests for each implementation.
Test failure should clearly feedback into fixes:
- Capture output from tests so failure can be diagnosed.
- Make sure failed tests can be run in isolation from their suite, so you can focus on fixing failing tests.
- How long is the mean time between test failure, fixing the faulty code and rerun of the test?