liveBook · Manning

Spring Boot

As explained in Testing Spring Boot Applications

A framework built on Spring that simplifies the creation and deployment of production-ready applications through convention-based configuration and integrated tooling.

Spring Boot is a Spring-based framework that simplifies application creation and deployment through convention-over-configuration defaults, integrated tooling, and coordinated dependencies. In testing, it connects application configuration, beans, test utilities, and compatible test libraries so tests can focus on behavior rather than lifecycle and setup code. section 1.0 section 1.4

Spring Boot testing conventions provide:

  • Use @SpringBootTest to load the application and override properties for a test scenario. section 1.4
  • Use @Autowired to access application beans, @MockitoBean to replace production collaborators, and MockMvc to exercise HTTP endpoints. section 1.4
  • Prefer Boot’s declarative setup to manually managing the ApplicationContext, component lifecycle, configuration variants, and test dependencies. section 1.0 section 1.3
  • Choose Spring-specific tooling deliberately because full-context tests provide convenience but can affect test-suite speed. section 1.0

Testing a widget endpoint

A test can load the application with @SpringBootTest, configure MockMvc, inject the repository, replace the external WidgetValidator with @MockitoBean, post a widget using mockMvc.perform(post("/widget").param("name", "test-widget")), assert 201 Created, and verify persistence through the repository. section 1.4

Listing 1.4 A typical Spring Boot Tests configuration.
@SpringBootTest(properties = "widget.id.step=5") #1
@AutoConfigureMockMvc #2
class AwesomeSpringBootTests {

  @Autowired
  private MockMvc mockMvc; #2

  @Autowired
  private WidgetRepository repository; #3

  @MockitoBean
  private WidgetValidator mockValidator; #4


}

The configuration listing shows how application loading, property overrides, MockMvc, repository access, and collaborator replacement fit together in one test. section 1.4

How Testing Spring Boot Applications covers it

How deep it goes
Explains declarative configuration, application-context integration, test doubles, HTTP testing, and setup tradeoffs without detailing Boot internals.
Examples
Uses a Widget REST application, a stubbed external validator, repository verification, and MockMvc POST requests as concrete examples.
What it assumes
Assumes familiarity with Spring annotations, application components, HTTP endpoints, repositories, and automated testing.
What you can do after
Apply Spring Boot testing with @SpringBootTest, @AutoConfigureMockMvc, @Autowired, @MockitoBean, and MockMvc.
How it connects
Connects Spring Boot with Spring Framework, Spring ApplicationContext, dependency injection, MockMvc, and Mockito-based test doubles.

Also explained in

Compare how 9 books explain Spring Boot →

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.