arrange_act_assert
This is an old revision of the document!
Table of Contents
Source: Software Testing course at ITMO university by Kochubeev Nikolay Sergeevich
Arrange Act Assert (AAA)
Time passes, and tests become unreadable. In just one test there can be way too much arrangement, several actions and dozens of checks. Such a test breaks the main principle: test must explain, not confuse.
Pattern AAA divides test into 3 logical blocks:
- arrange – environment and data preparation;
- act – calling the action being tested;
- assert – result check.
Arrange
- Create an object or a system you're checking.
- Set up dependencies (mock, stub, fake).
- Prepare the input data.
The test must not make a real connection to the database, it must use a fake or an in-memory storage.
Act
- Make one action – the one you're checking.
- Do not mix different calls, or else the test will end up checking several things.
Assert
- Compare the result to the expected one.
- Error messages must be informative.
- It is acceptable to have several asserts, if they test one scenario.
Comparing AAA and GWT
AAA and GWT are very similar:
- Arrange = Given.
- Act = When.
- Assert = Then.
AAA is used in testing code, and GWT is used in BDD scenarios, where it's important for them to be readable for the business.
AAA violations
- To many actions in Act – the test checks for several scenarios at once.
- Long and difficult arrangement – test is unreadable.
- No asserts or they're not obvious – unclear what is being checked.
arrange_act_assert.1757433764.txt.gz · Last modified: by plida
