Automated testing patterns
Testing patterns serve the goals of automated testing: specification, documentation, support for refactoring, and help to locate defects.
Published in
9 min readDec 10, 2021
Creating patterns to describe something creates nomenclature. Once you have a name for something, it’s easier to recognize when you see it again. The Productive Programmer
I’ll present the testing patterns that I apply in every project since they’ve proven very beneficial regarding the goals of automated testing:
- “Arrange, Act, Assert”: always divide tests into three parts;
- “One action per test”: focus on a single SUT ability per test;
- “One behavior per test”: don’t assert distinct behaviors in a single test;
- “Assert with the SUT”: avoid under-the-hood assertions like checking the database, using mocks or spies;
- “Arrange with the SUT”: avoid under-the-hood setups.
- “Create a SUT client”: if SUT calls are verbose, extract them to a reusable place;
- “Don’t make me think”: tests should have no logic and be complete, evident, and concise.
📝 The system under test (SUT) — the test subject, is whatever you’re testing. It can be a component, a web API, a…