arrange, act, assert

A three-step shape for a test: set up the starting state, perform the one behaviour under test, then check the observable result.

In more detail

Keeping the three steps visible makes a test read like a small specification and makes a failure point at one rule. Avoid hiding the rule inside helpers that make the failure hard to read.

Examples

In pytest: build the input, call the function once, then assert on the result.
In this course: Arrange builds only the data and objects the behaviour needs. Act is the single call under test, ideally with its result given a name. Assert compares that result with a value worked out by hand, which keeps failure reports short and makes the subject of the test easy to find.
lines = [(250, 2), (125, 4)]

charged = with_vat(subtotal(lines))

assert charged == 1200

Related terms

Taught in

References