Verification practices.
WHAT LEVELS TO WRITE
Unit tests for logic Integration tests for data access and endpoints A small number of end-to-end tests
WHAT MAKES CODE TESTABLE
Dependencies injected rather than created internally.
WHY
They can then be substituted.
WHAT TO SUBSTITUTE
Databases, external services, time and randomness.
WHY TIME AND RANDOMNESS
Otherwise tests fail intermittently, and intermittent tests get ignored.
WHAT TO USE FOR INTEGRATION TESTING OF WEB APPLICATIONS
The in-memory test host, which runs the application without a network.
WHAT TO USE FOR DATABASE TESTS
A real database of the same kind, in a container.
WHY NOT AN IN-MEMORY SUBSTITUTE
It behaves differently, and tests pass that should fail.
WHAT TO TEST SPECIFICALLY
- Authorisation: that a user cannot reach another's data
- Validation: that invalid input is rejected
- Error handling: that failures produce correct responses
WHAT TO RUN AUTOMATICALLY
Everything, on every change.
WHAT TO MEASURE
Coverage, as a signal rather than a target.