Testing is running software on purpose to find out whether it does what it should. A test cannot prove there are no bugs, but a good suite catches regressions, documents behaviour and lets you change code without fear. The skill is choosing a few cases that are likely to expose a failure.
Key concepts
- Levels: unit tests for small pieces, integration tests for parts together, end-to-end tests for whole flows.
- Test design: boundary values, equivalence classes, error paths and the cases nobody thought of.
- Isolation: test doubles such as stubs and mocks replace slow or unreliable dependencies.
- Determinism: a test that fails randomly teaches people to ignore failures; remove time, order and network dependence.
- Coverage and its limits: it shows what was run, not what was checked.
Vocabulary
- Assertion: a statement in a test that must be true, or the test fails.
- Regression: something that worked and stopped working.
- Fixture: the prepared state or data a test starts from.
- Property-based testing: checking general rules against many generated inputs.
What to study, in order
- Write unit tests for a small function with your language's standard test framework.
- Practise boundary values and error cases on a function that parses input.
- Replace a dependency with a fake, and test a piece that talks to a database or a clock.
- Write a property-based test and let it find a bug in your own code.
- Run tests on every change automatically, and track and fix flaky ones.