Skip to main content
InterviewHubPRO
Section Overview
Q5

Question 5 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

10%
Software Testing & QA (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

What is the AAA (Arrange-Act-Assert) Pattern and Given-When-Then?

junior LevelCode Examplesoftware-testingBasic

In Simple Words: A universal standard for writing clean, readable, and maintainable test cases:

  • Arrange (Given): Setup test fixtures, inputs, and mock return values.
  • Act (When): Execute the actual function or method under test.
  • Assert (Then): Verify that the output, state change, or mock invocations match the expected outcome.
typescript
test('calculates discount for VIP customers', () => {
  // 1. Arrange (Given)
  const cart = new ShoppingCart();
  cart.addItem({ id: 'item_1', price: 100 });
  const user = { isVip: true };

  // 2. Act (When)
  const total = cart.calculateTotal(user);

  // 3. Assert (Then)
  expect(total).toBe(80); // 20% discount applied
});