MEPX
Chapter 3 of 10All chapters

Chapter 3 of 10

What a good test looks like

Readable, isolated, deterministic.

The qualities

Arrange, act, assert. One reason to fail. A name that says what behaviour is expected, so a red test tells you what broke without opening the file.

  • Test behaviour through the public interface, not private internals.
  • Avoid logic in tests: an if statement in a test is a bug waiting to happen.

Determinism

A test that depends on the clock, the network, random values or the order of other tests will eventually lie. Inject those dependencies so the test controls them.