Testing - Pt 3 - Writing Tests

· testing oped

Tests should be fast to run and fast to write:

  1. Writing tests should not require time-consuming set-up of databases, DLLs or environments, automate anything of this nature.
  2. You should not require tacit knowledge of customised systems, no ones want to indulge in tedious manual set up. It's just cost.
  3. Ask yourself - is running someone else's tests should be possible with a single button?
  4. The tests themselves should not take long to write.

Don't confuse tests for production code:

  1. Don't worry too much about writing the most "effective Java" test code, or reuse. Fields don't need to be "private final".
  2. You don't need to enforce you coding standards on tests.

Test the behaviour, not the method (@Test void testMethodX anyone?):

  1. 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:

  1. Capture output from tests so failure can be diagnosed.
  2. Make sure failed tests can be run in isolation from their suite, so you can focus on fixing failing tests.
  3. How long is the mean time between test failure, fixing the faulty code and rerun of the test?

← Back to part 2 ~ On to part 4 →