liveBook · Manning

Integration test

As explained in Testing Spring Boot Applications

An integration test verifies that multiple independently developed units work correctly together, often including framework capabilities and selected external dependencies.

An integration test checks that independently developed units work together. In a Spring Boot application, it also checks their integration with Spring capabilities such as the web or data layer. It may include a database, but need not exercise every external dependency. Its scope sits between a focused unit test and a full end-to-end test. section 1.2

Spring Boot Test reduces the setup needed for this scope: it starts the application for tests, makes beans available through @Autowired, and cleans up afterward. With @SpringBootTest, it finds and runs the application's @SpringBootApplication class. Tests can exercise HTTP endpoints with MockMvcTester, inspect results or application state, and replace beans to stub external services. section 1.6 section 2.8

Listing 2.1 The test bundled in a Spring Initialzr-based project.
@SpringBootTest #1
class WeatherApplicationTests {

  @Test #2
  void contextLoads() { #2

  }

}

The generated @SpringBootTest class is a useful starting point, not a feature test: its empty contextLoads method establishes only that the application starts. Add actions and assertions to check application behavior. section 2.2 section 2.0

Choose the scope deliberately. A startup check can expose missing beans or invalid properties, but it cannot verify business logic. Integration tests suit user scenarios that exercise cooperating parts of an application. For complex logic with many input variations, prefer focused unit tests over repeatedly starting the full application and arranging extensive test state. section 2.2 section 2.7

How Testing Spring Boot Applications covers it

How deep it goes
Defines the scope and outlines startup, bean access, HTTP checks, and dependency replacement without deeply developing any one technique.
Examples
Uses an empty @SpringBootTest startup check and a weather-scoring unit test to distinguish integration checks from focused logic tests.
What it assumes
Assumes an existing Spring Boot application; starts from its generated test and introduces the basic pieces of an integration test suite.
What you can do after
Apply it via Spring Boot Test to check cooperating application parts while reserving focused unit tests for complex conditional logic.
How it connects
Relates integration tests to unit tests, end-to-end tests, the Spring web and data layers, and dependency mocking.

Also explained in

Compare how 40 books explain integration test →

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.