liveBook · Manning

Dependency graph

As explained in Testing Spring Boot Applications

A dependency graph is a graph representing components and the dependency relationships among them.

A dependency graph represents components as nodes and their dependency relationships as connections. In a Spring Boot test, the graph determines whether a selected configuration can start: every imported bean must have the components required to be wired. section 3.3.4

Graph scope is a practical testing concern. Importing one configuration can pull in dependencies several levels deep, enlarging the test context and undermining a focused test. Instead, keep configuration classes composable and supply missing dependencies through a custom test configuration, including stubs where behavior is unnecessary. section 3.3.4

Use the graph to choose an appropriate test boundary:

  • Select only focused configuration classes when the test should load a small application context. section 3.3.4
  • Provide missing components with @TestConfiguration rather than expanding the scope through multiple dependency levels. section 3.3.4
  • Prefer data-layer slices when repositories are the relevant leaves of the graph and loading the full context offers little value. section 5.6
Listing 3.12 Using the classes = {…​} parameter
@SpringBootTest(classes = { ThingConfiguration.class }) #1
class CustomClassesTests {

  // ... your test code ...


}

Shows how the classes parameter constrains the imported dependency graph in a Spring Boot test. section 3.3.4

Figure 3.1 Our test only imports the ThingConfiguration. The scope of the test is included in the box. The dashed arrows point from beans to the configuration classes in which they are defined, and the solid arrows represent dependencies. Through the GreenThing bean, our test has dependencies on components outside its scope.
ch03 f01 garniermoiroux

Visualizes configuration scope separately from dependency edges, including a bean that reaches outside the test boundary. section 3.3.4

How Testing Spring Boot Applications covers it

How deep it goes
Explains graph scope, multilevel dependency discovery, bean leaves, and stub substitution, but does not formalize graph algorithms.
Examples
Uses ThingConfiguration, GreenThing, YellowGizmo, BlueWidget, selected classes, and repository leaves as concrete graph examples.
What it assumes
Assumes familiarity with Spring beans and configuration classes while teaching how dependencies determine whether a selected test context starts.
What you can do after
Configure focused Spring Boot tests by identifying missing dependencies, supplying stubs, and selecting suitable data slices.
How it connects
Connects dependency graphs with Spring IoC containers, configuration classes, test slices, and application contexts.

Also explained in

Compare how 9 books explain dependency graph →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Testing Spring Boot Applications. The section links point to the parts of the book it draws on.