one reason to fail
The guideline that a single test should only be able to fail for one cause, even if it contains several assertions.
In more detail
People often quote the rule as one assertion per test, but the version that matters is one reason to fail. Several assertions about one returned value belong together, because they describe one behaviour. Assertions about unrelated behaviours belong in separate tests, because the first failure would hide the others.
Related terms
- assertion — A check that a condition is true, which stops a test or program with a failure if it is false.
- automated test — A small program that runs part of your code and checks that it did what you claimed it would.
- parametrized test — One test function run many times with different data, each run reported as a separate test case.
Taught in
- One Assertion Per Reason — Automated Testing, TDD & Quality Engineering
- Parametrised Tests — Automated Testing, TDD & Quality Engineering