Deeper walkthroughRead Write a Small Unit Test as a mechanism, not a recipe
Treat this as a sequence of observable decisions rather than one opaque command. Stage 1: Choose one behaviour of a small function and define the expected result for a controlled input. Stage 2: Arrange the input/state, call the function, then assert the observable result. Stage 3: Add at least one boundary or invalid case that could fail for a different reason. Final checkpoint: Run the test after a deliberate small code change to confirm that it can actually detect a regression.
MechanismFollow the transformation
Choose one behaviour of a small function and define the expected result for a controlled input.
Arrange the input/state, call the function, then assert the observable result.
Add at least one boundary or invalid case that could fail for a different reason.
EvidenceKnow what would convince you
- Trace a tiny input by hand and compare the runtime result.
- Inspect type, value/shape and any mutation/side effect explicitly.