Technical Medium Software Engineer Backend QA

How do you test a Spring Boot application at different levels?

Practise this question with AI feedback

Record your spoken answer or type your response to receive immediate scoring and STAR improvements.

💡 Suggested Approach & Sample Answer

Unit tests (fastest, most of the suite):
- Plain JUnit 5 and Mockito, no Spring context. Test services and domain logic with mocked dependencies through constructor injection.

Slice tests (part of the context):
- @WebMvcTest(OrderController.class) with MockMvc: request mapping, validation, JSON serialisation, error handlers and security rules, with services mocked via @MockitoBean (@MockBean before Boot 3.4).
- @DataJpaTest: repositories and queries against an embedded or Testcontainers database, rolled back after each test.
- @JsonTest for serialisation details.

Integration tests:
- @SpringBootTest loads the full application. Use Testcontainers for real PostgreSQL, Kafka or Redis instead of in-memory substitutes, so tests match production behaviour.
- Use @ServiceConnection (Boot 3.1+) to wire containers automatically.
- WireMock or MockRestServiceServer for external HTTP APIs.

Contract and end-to-end:
- Consumer-driven contracts (Spring Cloud Contract or Pact) between services.
- A few end-to-end tests for critical journeys only.

Speed tips: reuse the application context by keeping test configuration consistent, and avoid @DirtiesContext unless necessary.

🎯 What Interviewers Listen For

How would you answer this in a real interview?

Use our free AI mock practice tool to test your response, analyze speaking pacing, and refine your STAR structure.

🔗 Related Technical Questions