@ApplicationModuleTest loads a complete Spring Boot test context for one Spring Modulith application module. It includes the module’s beans and configuration while excluding other modules, making the context smaller than an application-wide test. section 5.5.2 section 5.8
Use the annotation with these practical defaults and boundaries:
- Detect the module from the test’s package by default, or select it explicitly with the module parameter. section 5.5.2
- Provide replacement beans when the selected module depends on excluded modules; @MockitoBean, test configurations, and @TestBean are available. section 5.5.2
- Replace external integrations when isolation matters, even when the module’s default implementation would otherwise be loaded. section 5.5.2
- Prefer @ModuleSlicing with annotations such as @WebMvcTest when the test should remain limited to a particular technical slice. section 5.8
Testing a weather module endpoint
Annotate the test with @ApplicationModuleTest and @AutoConfigureMockMvc. Stub the excluded CityService with @MockitoBean and replace WeatherDataService with a @TestBean returning deterministic weather. Configure the stubbed city, call /api/weather through MockMvcTester, and assert the HTTP status and JSON response.
