Loading…
JUnit 5, Mockito, Spring Boot tests, Testcontainers, contract testing
Automated testing shows up in every senior Java backend interview. Drill JUnit 5 (parameterized, nested, dynamic tests), Mockito patterns, @SpringBootTest slices, Testcontainers for real-database tests, contract testing, and advanced techniques (mutation, property-based, performance) — with the scenario and trade-off questions interviewers actually ask.
How to use this hub
1 modules cover java testing end-to-end. Open the first module, use Open question 1 on its landing page, and use Next at the bottom of each answer to stay in order.
Revision sheet
~12 min · 5 sections · save as PDF
Java testing interview questions cover the full testing pyramid — unit testing with JUnit 5 (lifecycle, parameterized tests, extensions), mocking with Mockito (verify, argument matchers, when not to mock), Spring Boot test slices, integration testing with Testcontainers, contract testing (Pact, Spring Cloud Contract), TDD discipline, performance testing, chaos testing, and the trade-offs between mocks vs real dependencies. This page covers JUnit, Mockito, Testcontainers and the testing-strategy questions that come up at every level.
Pyramid order: unit > integration > E2E.
@SpringBootTest + Testcontainers (real DB, real Kafka).The interview surface for this module breaks into these focus areas:
Thread.sleep."I'd unit-test the pure logic, integration-test the wiring with Testcontainers, contract-test the public API, and reserve E2E for the smoke-critical paths. Coverage is a signal, not a goal — mutation testing tells me whether tests *assert* anything."