Skip to content
BENIBIX Learn

Arrange-Act-Assert (AAA)

Development🧪 Testing & QualityTest Basics

Also known as AAA Pattern, Arrange Act Assert, AAA Test Pattern

A test in three steps. Set it up, run it, then check the result.

Think of it like

Think of it like a magic trick. You set up the cards, you do the trick, and then you show the card.

Example

Jack's test sets a price of 100, runs addTax and checks the answer is 120. Each step is one line.

Why it matters

Anyone can read a test shaped this way and see what it proves.

Definition

Arrange-Act-Assert is a simple shape for writing one test. First you arrange: you set up the inputs. Then you act: you run the one thing being tested. Then you assert: you check the result is what you expect. Keeping the three parts apart makes a test easy to read.

Example code

javascript
test("adds tax to the price", () => {
  const price = 100;            // Arrange
  const total = addTax(price);  // Act
  expect(total).toBe(120);      // Assert
});
Three lines, three steps: set up, run, check.
The three lit-up steps are arrange, act and assert.

Common mistake

Acting and asserting many times in one test. When it fails, you cannot tell which part broke.

Key takeaways

  1. 1
    Arrange. Set up the inputs.
  2. 2
    Act. Run one thing.
  3. 3
    Assert. Check the result.