A module test is a Spring Boot test whose application context contains every bean and configuration declared by one application module, while excluding other modules. It provides a vertical test slice across web, data, and technical layers without loading the entire application. section 5.5.2
Use the module boundary as the default scope, then provide excluded dependencies explicitly:
- @ApplicationModuleTest detects the module from the test package; override it with the annotation’s module parameter when necessary. section 5.5.2
- Stub services belonging to excluded modules with Mockito beans, test beans, or test configuration so the context can start. section 5.5.2
- Prefer a narrower @WebMvcTest with @ModuleSlicing when only module controllers require coverage; use the full module context for integrated module behavior. section 5.5.2
Testing a weather module
Annotate WeatherApiTests with @ApplicationModuleTest and @AutoConfigureMockMvc. Replace the excluded CityService with @MockitoBean, supply WeatherDataService with @TestBean, stub selected cities to return Paris, and assert the weather JSON response through MockMvcTester. section 5.5.2
