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








