Skip to content

Arrange-Act-Assert (AAA)

In one line

AAA is a test pattern: Arrange (set up data), Act (call the code), Assert (check the result). It improves test readability.

In simple words

Arrange-Act-Assert (AAA) is a simple pattern for structuring tests. It divides each test into three clear sections:

  1. Arrange: Set up everything the test needs — create test data, initialize variables, configure mocks. This is the 'given' part.
  1. Act: Execute the code being tested — call the function with the arranged inputs. This is the 'when' part. Usually just one line.
  1. Assert: Verify the result — check that the output, side effects, or state changes match expectations. This is the 'then' part.

The pattern improves readability by making the structure obvious. When you read a test, you can clearly see what's setup, what's the action, and what's being verified. Some teams even add blank lines or comments between sections.

Example

javascript
test('calculate total with discount', () => {
  // Arrange
  const items = [10, 20, 30];
  const discount = 0.1;

  // Act
  const total = calculateTotal(items, discount);

  // Assert
  expect(total).toBe(54); // 60 - 10%
});

The three sections are clearly separated: setup, execution, verification.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary