F.I.R.S.T principles of good test

Fast

Because we are going run tests very often when practicing TDD, each test should run under 1 second. Otherwise it would be unproductive. To achieve that, we should avoid using e.g Spring tests since the time to boot up is quite long.

Isolated

  • Tests do not depend upon each other. One test should run independently from all other tests.
  • Every tests can be run in any order.

Repeatable

  • The tests should not be dependent on environmental issues.
  • Never subject to network timing, memory usage, other processes, etc.

Self-verifying

  • Has binary result: pass or fail.
  • No interpretation is required.
  • Each tests should only have one assertions, it does not mean the test only have 1

Timely

  • Should be written before production code.

Workflow

  1. You are not allowed to write any production code until you have written a unit test that fails due to its absence.
  2. You are not allowed to write more of a unit test than is sufficient to fail. Failing to compile is failing.
  3. You are not allowed to write more of a unit test than is sufficient to cause the currently failing test to pass.