Skip to content

AAA Pattern

AAA

Easy — everyone uses thisTesting

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.