liveBook · Manning

Real dependency

As explained in The Art of Unit Testing 3e

A dependency whose actual implementation or external state is used during a test rather than a controlled substitute.

A real dependency is something a test uses as it actually exists: another component, service, clock, network, database, thread, or random-number generator. Because the test does not fully control it, its state or behavior can affect the result. section 1.8

Tests using real dependencies are integration tests. They exercise units working together, while unit tests isolate a unit from dependencies so behavior can be controlled and simulated consistently. section 1.8

Real dependencies make a test useful for checking collaboration, but introduce practical costs:

  • More possible failure points make the cause of a failed overall operation harder to locate. section 1.8
  • Changing shared code or data can make earlier tests fail and expose regressions: functionality that previously worked but no longer does. section 1.8
  • Use isolated tests when consistent, controllable simulation of a unit's behavior matters most. section 1.8
Figure 1.7 You can have many failure points in an integration test. All the units have to work together, and each could malfunction, making it harder to find the source of a bug.
01-07

A single operation can cross many units; any one of them can malfunction, so an integration-test failure identifies the operation but not necessarily its cause. section 1.8

How The Art of Unit Testing 3e covers it

How deep it goes
Contrasts integration and unit tests, then explains failure diagnosis and regression risks without detailing test implementation.
Examples
Uses an app, REST API, or UI button operation crossing functions, modules, and components, plus a multiple-failure-points figure.
What you can do after
Evaluate/understand why a test with real dependencies can verify collaboration yet be harder to diagnose and keep consistent.
How it connects
Connects real dependencies with integration testing, unit tests, regressions, networks, databases, and random number generators.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Unit Testing 3e. The section links point to the parts of the book it draws on.