JUnit runs automated Java tests, while Spring integrates with it through the SpringExtension to manage application lifecycles and test access to Spring beans. section 1.1
Spring-oriented JUnit tests typically rely on declarative configuration:
- @SpringBootTest lets Spring detect application configuration and prepare the test application context without imperative startup code. section 1.1
- The SpringExtension starts and stops the Spring ApplicationContext and makes configured beans available during tests. section 1.1
- Spring Boot’s curated test dependencies combine JUnit-oriented utilities with Spring-specific testing support. section 1.1
Declarative Spring Boot test setup
Annotating a test class with @SpringBootTest describes the required application setup; Spring discovers the configuration and performs startup and shutdown internally, leaving the test focused on its assertions. 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>
Shows a test-scoped Spring Boot test dependency in a Maven pom.xml. section 1.1


