Versions

org.springframework.boot:spring-boot-starter -> 2.7.0 & 2.7.9 org.springframework.boot:spring-boot-starter-test -> 2.7.0 & 2.7.9 org.junit.jupiter:junit-jupiter -> 5.8.2

Description

JUnit test methods annotated with org.junit.jupiter.api.Disabled are started / setup when part of a @SpringBootTest, if the @SpringBootApplication has Application Context errors.

I would have expected the disabled test not cause an application context loading / application start.

Example

Attached is a demo showing this behavior: - create a Spring Boot App via Spring Initialzr - add FailingListener an @EventListener for ContextRefreshedEvent that fails everytime. - add test contextStillLoads which is disabled - run the commands below, both tests are executed

unzip demo.zip
cd demo
./gradlew check --info

demo.zip

Comment From: wilkinsona

This is out of Spring Boot's control. From the javadoc of @Disabled:

When applied at the method level, the presence of this annotation does not prevent the test class from being instantiated. Rather, it prevents the execution of the test method and method-level lifecycle callbacks such as @BeforeEach, @AfterEach methods, and corresponding extension APIs.

Instantiating the test class requires the application context for the class so that dependencies can be injected into fields, the class's constructor, and so on.