A Note on Assertions Per Test

Learn about single-assertion style, separation application logic, and matchers.

We’ll often find that a common setup results in multiple assertions in a test. This is particularly true of integration tests. For example, when we wrote our initial test to add tasks back in Test-Driven Rails, we made several assertions about the project’s existence and its relationship with the tasks we’d just created.

There are two contrasting styles for writing tests with multiple assertions. In one style, the setup and all the assertions are part of the same test. If we were trying to test changes when we mark a task complete, then having all the assertions in the same test might look like this:

Get hands-on with 1200+ tech skills courses.