TB: Unit Tests
Definition
Automated tests that verify the behavior of individual, isolated units of code (functions, methods, classes) in isolation from the rest of the system. A unit test calls a unit with known inputs and asserts expected outputs, catching regressions and specification violations immediately.
Why it matters
Unit tests are the software analog of skin in the game: the developer puts their assumptions on the line. Code without tests is brittle in the same way advice without consequences is unreliable — no mechanism forces correctness. Well-written unit tests serve three functions: (1) regression detection — changes that break existing behavior surface immediately; (2) specification — tests document the intended behavior better than comments; (3) design pressure — code that is hard to unit test is usually poorly designed (tightly coupled, with hidden dependencies). The "test first" discipline (TDD) makes the design benefit explicit by forcing interface design before implementation.
Examples from reading
- No reading examples yet — will populate as books are ingested.
See also
- Strict with Yourself, Lenient with Others — maintaining a high test standard for your own code is the "strict with yourself" principle applied to software
- Skin in the Game — tests put the programmer's assumptions on the line; the discipline of writing tests creates accountability