Testing — Junior¶
Write tests around observable behavior. Use arrange, act, assert; name the scenario; cover normal, boundary, and expected failure cases.
sequenceDiagram
Test->>System: controlled input
System->>Dependency: required interaction
Dependency-->>System: controlled result
System-->>Test: observable outcome
Use a fake for a simple working dependency, a stub for fixed responses, and a mock only when the interaction itself is the contract. Control time, randomness, and shared state to prevent flakiness.
Test yourself¶
- What behavior does your assertion prove?
- When is a mock appropriate?
- Which uncontrolled input makes the test flaky?
- What important failure remains untested?
Continue to middle.md.