Structuring Test Functions
I recommend making sure you keep assertions at the end of test functions. This is such a common recommendation that it has at least two names: Arrange-Act-Assert and Given-When-Then.
Bill Wake originally named the Arrange-Act-Assert pattern in 2001.[11] Kent Beck later popularized the practice as part of test-driven development (TDD).[12] Behavior-driven development (BDD) uses the terms Given-When-Then, a pattern from Ivan Moore, popularized by Dan North.[13] Regardless of the names of the steps, the goal is the same: separate a test into stages.
There are many benefits of separating into stages. The separation clearly separates the “getting ready to do something,” the “doing something,” and the “checking to see if ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access