Skip to content

Rule 2 Test behaviours not layouts

Edward Baitsewe edited this page Nov 9, 2026 · 1 revision

Rule 2: Test behaviours, not layouts

Part one: wiring. Tests say what the system does, in sentences a person could check. They do not test how the code is arranged.

The short form of every rule is in BUILD_PHILOSOPHY.md, which is the version that counts. This page is the long form: why, where it shows today, and when not to use it.

Why

A test that checks structure (a private method was called, a class has a property) breaks every time the code is tidied, while the behaviour stays correct. People then stop trusting the tests. A test that checks behaviour only fails when the behaviour is wrong, so a red test always means something.

Where it shows in Slim Killer

When not to apply it

Some things only have a shape, not a behaviour: a template's HTML, a generated file. Test the one part that matters (the field is there, no inline styles) rather than the whole page.

Words

Behaviour, fake, quality gates. See Glossary.

Learn more

PHP 8.5 OOP Mastery, Rule 2 in its course philosophy, taught in module 5, testing and TDD. Course page.


Build philosophy

Clone this wiki locally