liveBook · Manning

Module test

As explained in Testing Spring Boot Applications

A module test is a Spring Boot test whose application context contains the beans and configuration declared by one application module.

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

How Testing Spring Boot Applications covers it

How deep it goes
Explains context composition, package detection, dependency stubbing, and a Web MVC alternative.
Examples
Tests a Weather module with MockMvcTester, a mocked CityService, a test WeatherDataService, and a Paris weather response.
What you can do after
Build module-scoped Spring Boot tests and replace excluded cross-module dependencies with test beans or mocks.
How it connects
Connects application context, test slices, Spring Boot tests, Mockito, test beans, and test configuration.

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.