Automated testing patterns

Testing patterns serve the goals of automated testing: specification, documentation, support for refactoring, and help to locate defects.

Luís Soares
CodeX

--

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

Photo by Jess Bailey on Unsplash

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

--

--

Luís Soares
CodeX
Writer for

I write about automated testing, Lean, TDD, CI/CD, trunk-based dev., user-centric dev, domain-centric arch, ...