Repository-focused tests verify mappings and queries with a narrower application context. Database-specific behavior may require the actual database engine.
Before you start
You should know Java classes, dependency injection and basic HTTP requests. Identify where a call crosses a framework-managed boundary. The snippets illustrate a focused mechanism; database configuration, application wiring and authentication must be supplied by the surrounding application when applicable.
The practical goal is to reason through this situation: A PostgreSQL query should be tested against PostgreSQL when it relies on its syntax or isolation behavior. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Select the tested boundary
Verify mappings and queries with a focused repository context.
Step 2: Use representative database behavior
Production-specific syntax and isolation need the actual engine or a justified compatible environment.
Step 3: Keep setup reproducible
Seed controlled records and isolate cleanup between runs.
Worked scenario
A PostgreSQL query should be tested against PostgreSQL when it relies on its syntax or isolation behavior.
An in-memory database accepting a query does not prove PostgreSQL uses the same syntax, constraints or isolation behavior. A repository slice against an isolated representative PostgreSQL instance checks that contract more directly while avoiding unnecessary web and application layers.
Common mistake
An in-memory database may pass behavior unsupported by production or fail supported production features.
Verify the behavior
Test empty, matching and conflicting data against the intended engine and inspect generated queries.
Interview exercise
Choose an integration database.
Answer and reasoning
Use an isolated representative engine and seed controlled data, keeping setup reproducible and cleanup reliable.
Continue learning
Compare the scenario with the Spring Boot interview questions and test your understanding with the Spring Boot MCQs. For terminology and implementation details, consult the reference material.