@SpringBootTest vs @ContextConfiguration
Fast recall
Quick revision
Core answer
Distinguishing Spring Boot features from core Spring Framework, showing awareness that Boot is a layer on top of Spring
Thinking they're equivalent or interchangeable, or not realizing @SpringBootTest is Boot-specific and won't work in plain Spring applications
Explain that @SpringBootTest uses Boot's TestContext bootstrapper and SpringApplication, while @ContextConfiguration is the core TestContext configuration annotation
Interview-ready guide
Interview answer
@SpringBootTest is Boot-specific: it uses Boot's test bootstrapper and SpringApplication, can discover the main Boot configuration, and participates in Boot auto-configuration and property loading. @ContextConfiguration is the core Spring TestContext annotation for configuration classes, locations, initializers, and a context loader. It does not enable Boot auto-configuration by itself, but the configuration it loads may scan or import other beans, so it is not limited to one manually listed bean. I use @SpringBootTest for broad Boot behavior, @ContextConfiguration for an intentionally defined Spring context, and a built-in slice when the test needs only one supported layer.
@SpringBootTest vs @ContextConfiguration
Direct Answer
@SpringBootTest uses Spring Boot's startup model and can discover the application's Boot configuration. @ContextConfiguration is the Spring TestContext annotation for declaring or detecting configuration classes, locations, initializers, and a context loader. It does not enable Boot auto-configuration by itself, although the classes you give it can import whatever configuration they need.
Common Mistakes & Pitfalls
Thinking they're equivalent or interchangeable, or not realizing @SpringBootTest is Boot-specific and won't work in plain Spring applications
Check your understanding
Answer these without looking back at the article.
- What is Spring Boot auto-configuration and how does it affect tests?
- When would you use @ContextConfiguration in a Spring Boot project?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.