Scrivio Interview library
LeadershipAdvanced7 min read · updated 12 November 2026

Your teams use H2 for repository tests in some services and Testcontainers in others, and several production incidents came from SQL differences. What standard would you set and how would you roll it out?

I would set one standard: repository and migration tests run against the same database engine and major version as production, using Testcontainers. To make that easy, the platform provides a shared test starter with approved container images, and CI agents that support containers and cache images. Services migrate when they next change persistence code, critical services by a fixed deadline, and fast unit tests stay for logic that never touches SQL.

Why this question is asked

This is a common situation in a company that grew quickly: each team chose its own way to test the database, and the choice that was fastest on day one, H2, keeps causing incidents. Interviewers ask it at this level because the technical answer is easy and the organisational answer is not. Anyone can say 'use Testcontainers'; the question is how to get 40 teams there without stopping feature work or creating resentment. In this answer, we will look at how to build the case from the incidents, write the standard so it is clear what it covers, make the right way the easy way, plan a rollout that teams can live with, and say what stays as it is.

1Start From the Incidents, Not From the Tool

Before writing any rule, I would collect the evidence. Go through the incident reports for the last year and tag each one whose root cause was a difference between the test database and production: a native query with PostgreSQL syntax that H2 never ran, a migration that failed on deploy, a partial unique index missing in the generated test schema, a lock behaviour that H2 did not reproduce. Note the customer impact and the time to recover.

Suppose that gives us six incidents in twelve months, two of them with several hours of degraded service. That is the argument. Teams respond much better to 'these six incidents would have been caught by a test' than to 'the platform team prefers Testcontainers'. It also shows which services carry the most risk, which we will need for the rollout order.

2Writing the Standard

The standard itself should be short and precise. Repository tests and migration tests run against the same engine and the same major version as production. A repository test means any test of code that sends SQL to the database: Spring Data repositories, native queries, JdbcTemplate code and anything that depends on locking or constraints. A migration test means running the full Flyway or Liquibase migration history against an empty database of the production version, which every service gets for free once its repository tests use migrations.

Just as important is what the standard does not require. It does not ask every test to start a container. Business logic that does not touch SQL, such as price calculations, validation or state machines, should keep running as plain unit tests in milliseconds. And it does not ban H2 from the build entirely; a library that genuinely targets any database may keep it. Being explicit about this keeps the standard from becoming 'containers everywhere', which teams would rightly push back on.

3Making the Right Way the Easy Way

A standard that costs each team a week of setup will be followed slowly and badly. So the platform team provides a shared test starter, a small library that every service adds as a test dependency. It contains the approved images, pinned to the production versions, a ready-made Spring test configuration, and the settings that make the suite fast.

Java
// In the shared starter: one definition of the approved database
@TestConfiguration(proxyBeanMethods = false)
public class PostgresTestConfiguration {
@Bean
@ServiceConnection
PostgreSQLContainer<?> postgres() {
return new PostgreSQLContainer<>(ApprovedImages.POSTGRES); // e.g. postgres:17.6, same major as prod
}
}
// In a service: the whole setup for a repository test
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@Import(PostgresTestConfiguration.class)
class InvoiceRepositoryTest { /* tests */ }

Because the container is a bean in a shared configuration, Spring's test context cache reuses the same context and the same container for every test class that imports it, so a service pays the start-up cost of a few seconds once per test run, not once per class.

The CI side matters as much. Every build agent must be able to run containers in the approved, security-reviewed way, and images must come through an internal registry mirror so that builds do not depend on public rate limits. Agents that keep a warm image cache make the first container start in seconds instead of waiting for a download. If CI cannot do this reliably, the standard will be blamed for every red build, so I would get this working for two pilot services before announcing anything.

4Rolling It Out Without Stopping Feature Work

Asking every team to migrate in the same quarter would compete with roadmap work and generate a lot of low-quality conversions. Instead, I would use a trigger and a deadline. The trigger: any change that touches persistence code, a repository, a migration or a native query, must move that service's repository tests to the standard in the same piece of work. That way the migration happens when the team already has the code in their heads. The deadline: services in the highest risk group, for example those involved in the incidents or handling payments, migrate by a fixed date regardless of other work.

Progress is tracked openly. A simple dashboard shows each service, whether it still has H2 on the test classpath, and its risk tier. Pilot teams write a short migration guide with the problems they hit, such as identifier case or sequence increments, so later teams are faster.

Step throughRolling out the database test standard
  1. Tag past incidents caused by SQL differencesBuilds the case and ranks services by risk
  2. Pilot the starter and CI setup on two servicesFix CI and docs before announcing
  3. Publish the standard and the starterClear scope: SQL code and migrations only
  4. Does a change touch persistence code?
    YesMigrate that service's repository tests nowNoWait for the trigger or the deadline
  5. Critical services migrate by a fixed datePayments and incident-related services first
  6. Track H2 usage per service on a dashboardRemove H2 from the starter BOM at the end

6 steps in order. Play them, or step through them one at a time.

5Keeping Fast Tests Fast

The last part is protecting the fast feedback that H2 gave people. Moving repository tests to containers is a good moment to look at what those tests actually check. Often half of them test business rules through the repository only because that was convenient. Those rules can move into plain unit tests that build domain objects directly. The repository tests that remain then focus on what only a database can tell us: queries, mappings, constraints, locking and migrations. The suite ends up both more truthful and not much slower, and teams see that the standard did not cost them their quick local loop.

6Follow-up questions

What if a team says the containers make their build too slow?

I would look at their numbers with them. Usually the cause is several different test contexts each starting their own container, or business logic tested through the database. Sharing one container through the starter and moving logic to unit tests normally brings the extra time down to seconds. If a real problem remains, that is useful feedback for the platform, not a reason for that team to be exempt.

How do you handle services that use a database other than PostgreSQL?

The standard is about the principle, same engine and major version as production, not about one product. The starter provides approved configurations for each engine we run in production, such as PostgreSQL and MySQL. For managed cloud databases without a container image, we test against the closest compatible engine and add a small set of tests against a real test instance.

How do you know the standard worked?

By the same measure that started it: incidents whose root cause was a test database difference. I would also track migration failures at deploy time, which should drop to near zero because every migration now runs in CI against the production version.

7Conclusion

In this answer, we built a standard from the incidents that motivated it. Repository and migration tests run on the same engine and major version as production, while logic that does not touch SQL stays in fast unit tests. A shared starter with approved images and CI agents that run and cache containers make the standard cheap to follow. Services migrate when they next change persistence code, critical ones by a deadline, with progress visible on a dashboard, and success is measured by the incidents and failed migrations that stop happening.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start with evidence: go through the last year's incidents and tag the ones caused by differences between H2 and production, so the case is about real outages and so I know which services carry the most risk.

Then, if they want more

Then I would set one clear standard: any test of code that sends SQL, and the migration history itself, runs against the same engine and major version as production. I would also say what it does not cover. Pure business logic stays in plain unit tests with no database, because those should run in milliseconds.

To make the standard cheap, the platform team ships a shared test starter with the approved images pinned to production versions and a ready Spring configuration using @ServiceConnection, so one import gives a team a working container that is shared across test classes.

CI agents must support containers safely and pull through an internal mirror with cached images, and I would prove that on two pilot services before announcing anything. For rollout, I would not ask everyone to migrate at once. Any change to persistence code triggers migrating that service's repository tests, and critical services, like payments, have a fixed deadline.

A dashboard shows who still has H2. I would measure success by incidents from SQL differences and failed migrations at deploy, which should both go close to zero.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your teams use H2 for repository tests in some services and Testcontainers in others...": https://scrivio-interview-library.netlify.app/java/integration-testing/d4da895513/