liveBook · Manning

Multiple act section

As explained in Unit Testing Principles, Practices, and Patterns

The execution phase of a test in which the operation or workflow under verification is performed.

A multiple-act section is a test execution phase containing more than one operation under verification. It is generally a code smell because the test checks multiple units of behavior, reducing focus and maintainability. section 8.5 section 8.8

Use the following rules when deciding whether multiple acts are justified:

  • Split related workflows, such as registration and deletion, into separate tests even when the first result can prepare the second operation. section 8.5
  • Never use multiple acts in a unit test; reserve the exception for tests involving out-of-process dependencies that are difficult to reset. section 8.8
  • Treat multistep tests as likely end-to-end tests and weigh their broader scope against understandability and modification cost. section 8.8

Registration followed by deletion

A fragile integration test registers a user, asserts successful persistence, deletes the same user, and asserts deletion. Refactor it into one registration test and one deletion test; each test then has a single act and a clearer failure meaning. section 8.5

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Defines the smell, demonstrates its refactoring, and limits the exception to difficult out-of-process dependencies.
Examples
Uses a registration-and-deletion integration test as the concrete example.
What it assumes
Assumes familiarity with arrange-act-assert structure and distinguishes unit tests from tests using external dependencies.
What you can do after
Apply single-act refactoring to make tests easier to understand, diagnose, and modify.
How it connects
Connects multiple act sections with arrange-act-assert structure, unit testing, integration testing, and end-to-end testing.

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.