The Arrange-Act-Assert (AAA), or 3A, pattern gives unit tests a uniform structure: prepare the system under test and dependencies, invoke one behavior, then verify its outcome. Outcomes may be return values, state changes, or collaborator calls. section 3.1
Use the three phases deliberately:
- Arrange the system under test (SUT) and its dependencies into the required state. section 3.1
- Act by calling the behavior under test and capturing its result when applicable. section 3.1
- Assert the expected result, final state, or interaction with a collaborator. section 3.1
- Split tests containing multiple Arrange, Act, or Assert sections; they usually verify several behaviors at once. section 3.7
- Treat a multi-line Act phase as an API warning: clients may need to perform coupled actions, risking invariant violations. section 3.7
Testing a calculator
Arrange two numbers and a Calculator named sut; act by calling Sum; assert that the result equals 30. Empty lines or phase comments make the boundaries visible without changing the test’s behavior.





