Spring Boot providesDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
@SpringBootTest for full application-context integration tests and a family of focused @...Test slice annotations for testing individual layers in isolation. Choosing the right approach keeps tests fast—slice tests start in milliseconds because they only load the beans relevant to a particular part of the application, while @SpringBootTest is reserved for end-to-end scenarios that need the full context.
@SpringBootTest web environment modes
@SpringBootTest creates an ApplicationContext through SpringApplication. Its webEnvironment attribute controls whether an embedded server is started and how it is configured.
- MOCK (default)
- RANDOM_PORT
- DEFINED_PORT
- NONE
Loads a web
ApplicationContext with a mock web environment. No embedded server starts. Use with @AutoConfigureMockMvc or @AutoConfigureWebTestClient for mock-based web testing.If your test is
@Transactional, the transaction rolls back at the end of each test method by default. With RANDOM_PORT or DEFINED_PORT, the HTTP client and server run in separate threads and therefore in separate transactions, so server-side transactions do not roll back automatically.Slice tests
Each slice annotation loads a narrowly scopedApplicationContext and restricts component scanning to the beans relevant to that layer. Beans that do not belong to the slice (such as @Component classes in a @WebMvcTest) are excluded, and collaborators are typically provided as @MockitoBean mocks.
@WebMvcTest — Spring MVC layer
@WebMvcTest auto-configures the Spring MVC infrastructure and limits scanned beans to controllers, ControllerAdvice, converters, filters, interceptors, and WebMvcConfigurer implementations. Regular @Component beans are not scanned. The slice also auto-configures MockMvc and MockMvcTester.
@DataJpaTest — JPA persistence layer
@DataJpaTest scans for @Entity classes and configures Spring Data JPA repositories. If an in-memory embedded database is available on the classpath, it is configured automatically. SQL queries are logged by default. Tests are transactional and roll back after each method.
TestEntityManager is an alternative to the standard JPA EntityManager designed for use in tests. It is also available in non-@DataJpaTest tests via @AutoConfigureTestEntityManager.
@DataMongoTest — MongoDB persistence layer
@DataMongoTest configures a MongoTemplate, scans for @Document classes, and sets up Spring Data MongoDB repositories. Regular @Component and @ConfigurationProperties beans are not scanned.
@WebFluxTest — Spring WebFlux layer
@WebFluxTest auto-configures the Spring WebFlux infrastructure and limits scanned beans to controllers, ControllerAdvice, converters, and WebFluxConfigurer implementations. It also auto-configures WebTestClient.
@WebFluxTest cannot detect routes registered through the functional web framework. For testing RouterFunction beans, import them with @Import or use a full @SpringBootTest.@JsonTest — JSON serialization
@JsonTest auto-configures the available JSON mapper (Jackson, Gson, or Jsonb) and provides JacksonTester, GsonTester, JsonbTester, and BasicJsonTester helpers for asserting on serialized and deserialized JSON.
@RestClientTest — REST client testing
@RestClientTest auto-configures Jackson, GSON, and Jsonb support, a RestTemplateBuilder, a RestClient.Builder, and a MockRestServiceServer. Use the value or components attribute to specify which beans under test to load.
Available test modules
Spring Boot ships dedicated-test modules for each major technology area. Each module provides focused slice annotations:
Web and API
Web and API
| Module | Annotation |
|---|---|
spring-boot-webmvc-test | @WebMvcTest |
spring-boot-webflux-test | @WebFluxTest |
spring-boot-restclient-test | @RestClientTest |
spring-boot-webclient-test | @WebClientTest |
spring-boot-graphql-test | @GraphQlTest |
Data
Data
| Module | Annotation |
|---|---|
spring-boot-data-jpa-test | @DataJpaTest |
spring-boot-data-jdbc-test | @DataJdbcTest |
spring-boot-jdbc-test | @JdbcTest |
spring-boot-mongodb-test | @DataMongoTest |
spring-boot-data-r2dbc-test | @DataR2dbcTest |
spring-boot-data-redis-test | @DataRedisTest |
spring-boot-data-cassandra-test | @DataCassandraTest |
spring-boot-data-couchbase-test | @DataCouchbaseTest |
spring-boot-data-elasticsearch-test | @DataElasticsearchTest |
spring-boot-data-neo4j-test | @DataNeo4jTest |
spring-boot-jooq-test | @JooqTest |
JSON and other
JSON and other
| Module | Annotation |
|---|---|
spring-boot-test-autoconfigure | @JsonTest |
spring-boot-micrometer-metrics-test | metrics support |
spring-boot-micrometer-tracing-test | tracing support |
spring-boot-webservices-test | @WebServiceClientTest, @WebServiceServerTest |