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
Notes are being added. Planned topics:
| 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. - MockMvc — test Spring MVC controllers without a real server; use with
@WebMvcTestfor speed. - @DataJpaTest — test repositories with an in-memory H2 database (or Testcontainers for realism).
- Testcontainers — the current gold standard for integration tests; Docker-based environments that match production.
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.