Testing Spring Applications
Fast, trustworthy tests at every layer.
Prove BookVault works and keep it working. The Spring test stack, fast web and data slice tests, mocking beans, real-database integration tests with Testcontainers, testing security, and a sane overall strategy.
Lessons in this stage
- 01
The Spring Test Stack
IntermediateWhat spring-boot-starter-test gives you, and when to load the whole context with @SpringBootTest versus a thin slice.
14 min - 02
Web Slice Tests with @WebMvcTest
IntermediateTest controllers in isolation with MockMvc - routing, validation, status codes, and JSON - without a database.
16 min - 03
Data Slice Tests with @DataJpaTest
IntermediateTest repositories and queries against a real (test) database, with the rest of the app left out.
14 min - 04
Mocking Collaborators
IntermediateReplace a bean in the context with a Mockito mock using @MockitoBean, so a slice test stays focused.
14 min - 05
Integration Tests with Testcontainers
AdvancedRun tests against the real database engine in a throwaway Docker container - no more H2-vs-production drift.
18 min - 06
Testing Secured Endpoints
IntermediateAssert that your access rules actually work - authenticated, anonymous, and wrong-role requests.
14 min - 07
Test Strategy, Data & CI
IntermediateThe test pyramid, choosing the right test for each job, managing test data, and running it all in CI.
14 min
Ready to test yourself?
Take the stage assessment to check your mastery. Pass it to earn a stage badge toward your Javaneer certificate.