liveBook · Manning

Contract testing

As explained in Grokking Software Architecture

An individual test that verifies a component conforms to an agreed behavioral contract.

Contract testing checks whether different components honor the same behavioral promise. To test the Liskov Substitution Principle, run the parent class’s unit tests against each subclass; a failure reveals behavior that callers cannot safely depend on. section 3.4.3

Test the player contract

If Player tests require a player to move away from the net, run those tests against Goalie and Midfielder too. A Goalie that fails has broken the parent class’s contract. section 3.4.3

How Grokking Software Architecture covers it

How deep it goes
Explains how to reuse parent-class unit tests across subclasses, without detailing a separate test framework or setup.
Examples
Uses Player tests for moving away from the net to check Goalie and Midfielder behavior.
What it assumes
Assumes a parent class with unit tests and subclasses whose behavior can be checked against them.
What you can do after
Diagnose substitution failures by running parent-class behavior tests against subclasses.
How it connects
Links unit testing and inheritance to the Liskov Substitution Principle.

Also explained in

Compare how 7 books explain contract testing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.