Java Integration testing
Tests against real dependencies, and the trade-off between fidelity and how long the build takes.
3 concepts · 9 interview questions
What this topic covers
Every concept in integration testing, and the questions each one gets asked as. Where a question links, it has a full write-up.
Testcontainers and real infrastructure
Running the actual database in a container removes the gap between an in-memory substitute and production, at the cost of startup time.
- Why test against a real database rather than H2?
- How do you keep container-based tests fast?
- How do you isolate tests that share a database?
How much to wire up
An integration test can load a whole application context or a single slice. The slice is faster and narrower; the full context catches wiring problems nothing else will.
- What is the difference between a slice test and a full context test?
- How do you test a REST controller without starting a server?
- When is an end-to-end test worth its cost?
Test data
Shared fixtures make tests fast to write and impossible to read. Building the minimum data each test needs keeps the intent local.
- Shared fixtures or per-test data?
- How do you stop tests depending on each other's data?
- How do you test code that depends on the current time?