liveBook · Manning

@ApplicationModuleTest

As explained in Testing Spring Boot Applications

@ApplicationModuleTest is a Spring Modulith annotation that loads the beans and configuration of a selected application module for testing.

@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.

How Testing Spring Boot Applications covers it

How deep it goes
Explains package detection, module overrides, excluded dependencies, replacement beans, and contrast with narrower test slices.
Examples
Demonstrates a weather endpoint test using MockMvcTester, a stubbed CityService, deterministic weather data, and JSON assertions.
What it assumes
Assumes Spring Boot testing and Spring Modulith dependencies, while teaching module selection and dependency stubbing.
What you can do after
Apply it via a module-scoped Spring test while supplying replacements for excluded module dependencies and external services.
How it connects
Connects Spring Boot testing with Spring Modulith modules, @ModuleSlicing, @WebMvcTest, @MockitoBean, and @TestBean.

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.