Interaction testing
Interaction testing is a testing technique that verifies how a unit under test interacts with its collaborators, such as which calls it makes and with what parameters.
Test Driven: Practical TDD and Acceptance TDD for Java Developers
Interaction-based testing verifies behavior by checking interactions between the system under test and its collaborators.
- How it is used
- Uses interaction testing to verify collaboration with difficult dependencies without relying on their real implementations.
- How deep it goes
- Contrasts state and interaction testing, then walks through recording expectations and replaying a mock.
- Examples
- Uses an OrderProcessor with a mock PricingService and contrasts it with checking a list’s state after adding an item.
- What you can do after
- Apply it via EasyMock by recording expected calls and responses, switching to replay mode, and exercising the object under test.
The Art of Unit Testing 3e
A testing technique that verifies how a unit of work interacts with its outgoing dependencies, including the calls made and their parameters.
- How it is used
- Checks calls from isolated units to dependencies they do not control.
- How deep it goes
- Defines mocks, stubs, exit points, injection approaches, and overspecification trade-offs without detailing framework internals.
- Examples
- Uses a logger call, mock assertions, dependency injection variants, and expectations that become fragile through overspecification.
- What you can do after
- Diagnose dependency-boundary behavior by injecting mocks and verifying important calls with their parameters.
Read how The Art of Unit Testing 3e explains interaction testing →
What to know first
- stubA stub is a minimal or generated stand-in for a software component or operation that exposes an interface while supplying placeholder, controlled, or delegated behavior.
- test doubleA test double is a substitute for a real dependency or collaborator that provides controlled behavior or enables interaction observation during testing.
Related concepts
- state-based testingcontrasts with · State-based testing is a testing style that verifies behavior by examining the observable state of the system or its collaborators after an operation.
- mockinguses · Mocking is a testing technique that replaces a dependency or collaborator with a controlled substitute to simulate behavior, isolate code, or inspect interactions.
- interaction assertionused by · An interaction assertion is a test check that verifies whether code interacts with a dependency as expected.
- stubcontrasts with · A stub is a minimal or generated stand-in for a software component or operation that exposes an interface while supplying placeholder, controlled, or delegated behavior.
Questions about interaction testing
What is interaction testing?
Interaction testing is a testing technique that verifies how a unit under test interacts with its collaborators, such as which calls it makes and with what parameters.
Which Manning books explain interaction testing?
Test Driven: Practical TDD and Acceptance TDD for Java Developers and The Art of Unit Testing 3e.
What should I know before learning interaction testing?
Manning books that teach interaction testing usually introduce stub and test double first.
What is the difference between interaction testing and state-based testing?
Interaction testing is a testing technique that verifies how a unit under test interacts with its collaborators, such as which calls it makes and with what parameters. State-based testing is a testing style that verifies behavior by examining the observable state of the system or its collaborators after an operation.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

