Testing
A Java backend engineer who cannot write good tests is considered junior regardless of other skills. This domain covers the full testing pyramid: fast unit tests with JUnit 5 and Mockito, integration tests with Spring Boot test slices, and realistic end-to-end tests using Testcontainers to spin up real databases in CI.
What You'll Find Here
| Topic | Description |
|---|---|
| JUnit 5 | @Test, @ParameterizedTest, @BeforeEach, lifecycle, assertions, assumptions. |
| Mockito | @Mock, @InjectMocks, when(...).thenReturn(...), verify, ArgumentCaptor. |
| Spring Boot Test Slices | @WebMvcTest, @DataJpaTest, @JsonTest — fast partial-context tests. |
| Integration Tests | @SpringBootTest with TestRestTemplate; full-context tests. |
| Testcontainers | Running real PostgreSQL, MySQL, Redis, Kafka in Docker containers during tests. |
| MockMvc & WebTestClient | HTTP-level controller testing without a running server. |
Learning Path
- JUnit 5 — the basics (
@Test,@BeforeEach,assertThrows) are required before everything else. - Mockito —
@Mockstub setup andverifyinteraction testing are the day-to-day tools. - Spring Boot Test Slices —
@WebMvcTestand@DataJpaTestfor fast, focused Spring tests. - MockMvc & WebTestClient — test Spring MVC controllers without a real server; use with
@WebMvcTestfor speed. - Testcontainers — the current gold standard for integration tests; Docker-based environments that match production.
- Integration Tests —
@SpringBootTestfull-stack tests that tie all the above together.
Quick Revision
- Testing Overview — key concepts, quick-reference table, and top 5 interview questions on one page.
- Testing Interview Questions — 20 Q&A questions organized by Beginner / Intermediate / Advanced.
Related Domains
- Spring Boot — Spring Boot test slices are the primary testing tool.
- Databases — Testcontainers integrates with all major databases for realistic integration tests.
- Docker — Testcontainers uses Docker under the hood.