Repaso
Español
TestingCoreTST-13

What is the Arrange-Act-Assert pattern?

Options

  1. A deployment process for the releases of a team
  2. Setup, one action, then assertions on the result (Correct option)
  3. A mocking library that is used for Python tests
  4. An Agile ceremony that teams hold every sprint

Answer

Structure each test as setup, a single action under test, then assertions on the outcome

Why

A clear test has three parts:

  • Arrange: prepare data and objects.
  • Act: do the ONE thing being tested.
  • Assert: check the result.

One behavior per test, with a descriptive name like test_withdraw_more_than_balance_raises, makes failures easy to understand.

def test_withdraw_reduces_balance():
    account = Account(balance=100)      # Arrange
    account.withdraw(30)                # Act
    assert account.balance == 70        # Assert

Remember

Arrange → Act → Assert.

Key terms

Practice this question in Repaso