The AAA pattern of writing tests
The AAA pattern of writing tests refers to the initials of the words arrange, act, and assert. This pattern provides a clean approach to organizing the instructions that become part of a test case. Following this pattern also enhances the readability of the test cases. The following points give a brief explanation of all three phases of the AAA pattern that help you write clean, organized, and readable tests:
- Arrange: This is the first of all the phases. In this phase, you arrange the inputs needed for the function that you are about to act on. You can also arrange and set expectations such as expected output assigned to the variables that you can use in the assert phase.
- Act: Having made arrangements for the test, we then act on the function we want to test. This could be done by invoking a call to the function under test. If any input arguments are needed by the function, we can pass them on to the function under test based on the arrangements...