liveBook · Manning

@SpringBootTest

As explained in Spring in Action, Sixth Edition

@SpringBootTest is a Spring Boot testing annotation that loads an application context with Spring Boot test support.

@SpringBootTest tells JUnit to bootstrap a test with Spring Boot capabilities and load the Spring application context. It is the test-class counterpart of calling SpringApplication.run() in a main method. Even an empty test method checks whether the application context can be created successfully. section 1.2.2

A baseline application test

package tacos; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest public class TacoCloudApplicationTests { @Test public void contextLoads() { } } The empty contextLoads method still prompts the annotations to load the application context; configuration problems cause the test to fail. Run it with ./mvnw test. section 1.2.2

Listing 1.3 A baseline application test
package tacos;
 
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
 
@SpringBootTest                            #1
public class TacoCloudApplicationTests {
 
  @Test                                    #2
  public void contextLoads() {
  }
 
}

View the complete baseline application-test listing. section 1.2.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains context loading and composite annotation behavior, but defers the annotation's additional capabilities.
Examples
Uses TacoCloudApplicationTests with an empty contextLoads test and the ./mvnw test command.
What it assumes
Assumes a Spring Boot project with JUnit 5 support and teaches context testing from a minimal empty method.
What you can do after
Diagnose configuration changes that prevent the Spring application context from being created.
How it connects
Connects JUnit 5, Spring application context, SpringApplication.run(), @SpringBootApplication, and SpringExtension.

Also explained in

Compare how 2 books explain @SpringBootTest →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.