AAA Pattern
AAA
ELI5 — The Vibe Check
AAA stands for Arrange, Act, Assert. It's the recipe for writing a test: first set up the stuff you need (Arrange), then do the thing you're testing (Act), then check the result (Assert). Every good test follows this structure — it makes tests readable and clear.
Real Talk
The Arrange-Act-Assert pattern structures a test into three clear phases. Arrange: set up preconditions and inputs. Act: execute the code under test. Assert: verify the expected outcome. This separation makes tests readable, maintainable, and communicates intent clearly.
Show Me The Code
test('calculates total with discount', () => {
// Arrange
const cart = new ShoppingCart();
cart.add({ price: 100 });
cart.applyDiscount(0.1); // 10% off
// Act
const total = cart.getTotal();
// Assert
expect(total).toBe(90);
});
When You'll Hear This
"Structure your tests with AAA — it makes them readable for the whole team." / "What's the 'act' in this test? It's not clear."
Related Terms
Arrange Act Assert
Arrange Act Assert is just the full name for AAA.
Given When Then
Given When Then is AAA's cousin from the BDD world. Given = the setup situation. When = what the user/system does. Then = what should happen as a result.
TDD (TDD)
TDD means you write the test BEFORE you write the code.
Test Case
A test case is one specific scenario you want to check. 'Does the login work with a correct password?' — that's a test case.