What is the Arrange-Act-Assert pattern?
Options
- A deployment process for the releases of a team
- Setup, one action, then assertions on the result (Correct option)
- A mocking library that is used for Python tests
- 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 # AssertRemember
Arrange → Act → Assert.