spring-boot-starter-test is Spring Boot’s curated testing dependency. It bundles the core libraries, integrations, and annotation-driven tooling needed for most application tests, including test execution, assertions, mocking, and Spring test support. section 1.1 section 1.6
Choose the starter according to the application surface being tested:
- Use spring-boot-starter-test for core Boot application testing without web capabilities. section 1.1
- Use spring-boot-starter-webmvc-test or spring-boot-starter-webflux-test when web-specific testing support is required; each includes the core test starter. section 1.1
- Use dedicated Spring portfolio test starters for areas such as REST clients, security, data, or batch processing. section 1.1
Listing 1.1 The spring-boot-starter-webmvc-test dependency in the pom.xml of a typical Boot project
<dependencies>
<!-- ... -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope> #1
</dependency>
</dependencies>
Declare the testing starter with test scope so its dependencies remain available to test code rather than production code. section 1.1
Spring Boot’s testing machinery uses annotations to discover configuration, start the application before tests, synchronize its lifecycle with test classes, shut it down afterward, and perform cleanup. Tests can access beans with @Autowired, update configuration, and replace existing beans. This approach is useful for user scenarios that exercise the application as a whole, but it is heavier than focused unit testing and can become unwieldy for fine-grained conditional logic or state-heavy tests. section 1.1 section 1.6
