Quick revision
The short answer
The standard makes Testcontainers with @ServiceConnection (Spring Boot 3.1 and later) the default, so tests run against the same engines and versions as production, delivered through a shared test library with container definitions pinned to the platform's supported versions. It states which tests must use real infrastructure, such as persistence, messaging and migrations, and which should be slices or unit tests. It plans CI capacity, with Docker on runners, image caching and limits on parallel containers per job, and keeps third-party services stubbed, for example with WireMock, verified separately by contract tests.
What to remember
In this answer, we defined a standard where integration tests use real engines through Testcontainers and @ServiceConnection, delivered by a shared library with versions pinned to the platform's supported versions. The standard says which code must be tested against real infrastructure and which belongs in slices or unit tests, plans CI capacity with Docker on runners, image caching and container limits, keeps third-party services stubbed with WireMock and verified by contract tests, and rolls out through pilots and the service template.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The standard makes Testcontainers with @ServiceConnection (Spring Boot 3.1 and later) the default, so tests run against the same engines and versions as production, delivered through a shared test library with container definitions pinned to the platform's supported versions. It states which tests must use real infrastructure, such as persistence, messaging and migrations, and which should be slices or unit tests. It plans CI capacity, with Docker on runners, image caching and limits on parallel containers per job, and keeps third-party services stubbed, for example with WireMock, verified separately by contract tests.
Why this question is asked
With 60 teams on shared CI runners, an integration-testing standard is as much about capacity and consistency as about tests. Without one, some teams test against H2 and miss PostgreSQL bugs, others start a dozen containers per job and starve their neighbours, and each team pins different versions. Interviewers ask this to see whether we can write a standard that protects quality, fits shared infrastructure, and is easy enough that teams actually follow it. In this answer, we will set the default approach, describe the shared library, define where real infrastructure is required, plan CI capacity, handle third-party services, and cover rollout.
1The Default: Real Engines Through Testcontainers
The core rule is that integration tests run against the same database, broker and cache engines, at the same major versions, as production. In-memory substitutes such as H2 for PostgreSQL or an embedded broker are not accepted for integration tests, because the defects we want to catch there are engine-specific: SQL dialect, constraints, locking, JSON types, migration scripts, consumer group behaviour.
Testcontainers makes this practical by starting the real engines in Docker, and Spring Boot's @ServiceConnection, available since Boot 3.1, wires them into the application without properties. Together they make the right thing about as easy as the wrong thing, which is what a standard for 60 teams needs.
2A Shared Test Library
The platform team owns a test library that every service adds as one test dependency. It contains container definitions for each supported engine, with image versions matching what the platform supports in production, ready-made configurations that tests import, and examples.
- Service testsextend shared bases, choose test layers
- Platform test librarycontainer beans, pinned versions, examples
- Testcontainers and @ServiceConnectionstart engines, wire connections
- Shared CI runnersDocker, image cache, container limits
4 layers, from the top down. Step through them one at a time.
Notice what this centralises. When the platform moves to PostgreSQL 18, one library release changes the version for every team, and their tests tell them before production does whether anything breaks. Teams on an older supported version pick the matching library version. The library also sets sensible test defaults, such as small connection pools.
3Which Tests Use Real Infrastructure
Real infrastructure is expensive compared with a unit test, so the standard says where it is required and where it is not. Persistence code, meaning repositories, custom queries and mappings, must be tested against the real database. Messaging code, meaning producers, listeners, serialization and error handling, must be tested against the real broker. Database migrations must run against the real engine in the build. Everything else, business logic, controllers, validation, belongs in unit tests and slices such as @WebMvcTest.
Writing this down prevents both failure modes: teams skipping real infrastructure for persistence, and teams wrapping every logic test in a full context with five containers.
| Code under test | Required test kind | Infrastructure |
|---|---|---|
| Business rules | Unit test | None |
| Controllers, validation, security rules | @WebMvcTest slice | None, mocks for services |
| Repositories, queries, mappings | @DataJpaTest or integration | Real database container |
| Migrations | Run in every build | Real database container |
| Producers and listeners | Integration test | Real broker container |
| Calls to third-party APIs | Client tests plus contracts | WireMock stub |
4Planning CI Capacity
On shared runners, containers compete for CPU, memory and disk. The standard needs agreements with the CI team. Every runner provides a working Docker environment, or a remote Docker host, that test jobs can reach. Standard images are pre-pulled onto runners or served from a registry mirror, so a build never downloads PostgreSQL from the internet. And each job has a limit on concurrent containers, for example at most three running at once, enforced by the shared library starting containers once per JVM and by limiting parallel forks.
I would also ask the CI team for a dashboard of container start times and runner saturation. If a runner pool is consistently saturated at 3 pm, that is a capacity decision to make with data, not a reason for each team to cut real-infrastructure tests on its own.
5Third-Party Services: Stubs and Contracts
External services, such as a payment provider or a shipping API, are not run in containers and not called from CI. Tests use WireMock, a local HTTP server that returns responses we define, including errors and slow responses, so we can test the client's behaviour in failure cases that the real sandbox would rarely produce. Because a stub can drift from the real API, the standard pairs stubs with contract tests: between our own services, consumer-driven contracts verified in the provider's build; for third parties, recorded examples checked against the provider's published schema or sandbox in a separate scheduled job, so a sandbox outage never blocks a merge.
6Rolling It Out to 60 Teams
I would roll the standard out through the shared library first, then the documentation. Two or three pilot teams adopt it with the platform team's help, we measure build time and escaped defects before and after, and the result becomes the example. The standard is then part of the service template, so new services start compliant, and existing services adopt it as they next work on their tests, with a deadline only for services still testing persistence against H2. A short checklist in code review, real database for repositories and no third-party calls in CI, keeps it from drifting.
7Follow-up questions
What about teams on an older database version?
The library publishes containers for every version the platform supports, so a team on PostgreSQL 16 tests against 16. The rule is to match your production version, and the library makes the supported versions available.
How do you stop one team's tests from starving the runners?
Through limits built into the shared library and CI configuration: containers start once per JVM, parallel forks are capped, and job resource limits are set by the CI team. Measured saturation then drives capacity decisions.
Is H2 ever acceptable?
For a quick experiment, perhaps, but not for tests that claim to check persistence. The cost of a real PostgreSQL container is a few seconds per JVM, which is small compared with an escaped dialect bug.
8Conclusion
In this answer, we defined a standard where integration tests use real engines through Testcontainers and @ServiceConnection, delivered by a shared library with versions pinned to the platform's supported versions. The standard says which code must be tested against real infrastructure and which belongs in slices or unit tests, plans CI capacity with Docker on runners, image caching and container limits, keeps third-party services stubbed with WireMock and verified by contract tests, and rolls out through pilots and the service template.
Open with
The default in my standard would be Testcontainers with @ServiceConnection, so integration tests run against the same engine and major version as production instead of H2 or embedded substitutes.
Then, if they want more
To make that easy for 60 teams, the platform would own a shared test library with container definitions for PostgreSQL, Kafka and Redis, pinned to the versions the platform supports, plus base configurations and examples, so a service imports one class and makes no version choices.
The standard would say where real infrastructure is required: repositories and queries, messaging, and migrations. Business logic and controllers go in unit tests and slices like @WebMvcTest, so we do not pay for containers where they add nothing.
Because CI runners are shared, I would agree capacity rules with the CI team: Docker available on every runner, standard images pre-pulled or mirrored, containers started once per JVM, and a cap on concurrent containers and forks per job, with a dashboard of start times and saturation.
External third-party services stay out of CI: tests use WireMock stubs, including failure cases, and contract tests or a scheduled sandbox check catch drift. I would roll it out through two or three pilot teams, then bake it into the service template so new services start compliant.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- PostgreSQL 16, PostgreSQL 18, Spring Boot 3.1
- 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.
- Official documentation
- Spring Boot reference, Testing
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 "Define a company standard for integration testing of Spring Boot services against real...": https://scrivio-interview-library.netlify.app/spring-boot/spring-boot-test/0c790ab880/