Testing in isolation.
WHAT A UNIT TEST SHOULD BE
Fast Independent Repeatable Self-verifying Written close to the code
WHAT INDEPENDENT MEANS
Running in any order, alone or together.
WHAT BREAKS THAT
Shared state Database dependence Fixed ports or files Reliance on execution order
WHAT THE STRUCTURE SHOULD BE
Arrange the situation Act Assert the outcome
WHAT TO ASSERT
The behaviour, not the implementation.
WHY
Tests asserting implementation break on every refactor without finding defects.
WHAT TO TEST
Public behaviour Edge cases Error conditions
WHAT NOT TO TEST
Private methods directly Framework behaviour Trivial accessors
WHAT MAKES CODE TESTABLE
Dependencies supplied rather than constructed Functions with clear inputs and outputs Logic separated from input and output
WHAT UNTESTABLE CODE INDICATES
A design problem, usually.
WHAT TO DO
Change the design, rather than writing elaborate tests around it.
WHAT TO AVOID
Tests with many assertions Logic inside tests Tests depending on time or randomness