Unit vs Integration Test
Fast recall
Quick revision
Core answer
Whether the candidate understands the testing pyramid and knows when each test type is appropriate in a Spring Boot project.
Using @SpringBootTest for service tests and calling them unit tests, or thinking unit tests always require Spring context.
Explain that the useful distinction is the behavior boundary: a unit test isolates a small unit, while an integration test checks collaboration across a real boundary
Interview-ready guide
Interview answer
A unit test checks a small unit of behavior in isolation and normally does not start Spring.
Its collaborators may be lightweight real objects, fakes, or mocks. An integration test checks that parts work together across a real boundary. In Spring Boot that could be a web slice, a repository with a database, a broad ApplicationContext, or a running HTTP server.
For example, I would unit-test an order discount with a controlled repository result, then use @DataJpaTest to prove that the real order mapping and query work with the configured test database. Integration tests usually cost more because they create more infrastructure or perform I/O, but there is no fixed timing or correct percentage.
I choose the smallest boundary that can prove the requirement, then add realistic integration coverage where mocks cannot expose wiring, mapping, persistence, or protocol errors.
Unit vs Integration Test
Direct Answer
A unit test checks a small unit of behavior in isolation and normally does not start Spring; collaborators may be real lightweight objects, fakes, or mocks. An integration test checks that multiple parts work together. In a Spring Boot project that may mean a test slice, a full ApplicationContext, a real database, or an HTTP boundary—Spring startup is common, not part of the definition.
Common Mistakes & Pitfalls
Using @SpringBootTest for service tests and calling them unit tests, or thinking unit tests always require Spring context.
Check your understanding
Answer these without looking back at the article.
- What annotations does Spring Boot provide for slice-based integration tests?
- When would you prefer @WebMvcTest over @SpringBootTest?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.