test naming
Choosing test function names that state the behaviour and the condition, so a failure summary reads as a sentence.
In more detail
A useful shape is subject, then behaviour, then condition, as in test_a_full_discount_makes_the_price_zero. Numbered names such as test_discount2 tell a reader nothing. Domain words in names also make the suite selectable with -k.
Related terms
- pytest -k — The pytest option that runs only tests whose names match a substring or a small expression using and, or and not.
- --collect-only — A pytest option that lists every test it would run without running any of them.
- given, when, then — A way of describing a test or requirement as a starting situation, an event, and the expected outcome.
Taught in
- Naming Tests For Readability — Automated Testing, TDD & Quality Engineering