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.
Visualizes configuration scope separately from dependency edges, including a bean that reaches outside the test boundary. section 3.3.4








