Scrivio Interview library

Integration testing and Testcontainers

22 questions in 6 subtopics.

Testcontainers

ConceptFoundations5 min read
Before @ServiceConnection existed, how were container ports passed to Spring, and when is @DynamicPropertySource still needed?
CodingFoundations6 min read
Show how to run a Spring Boot repository test against a real PostgreSQL using Testcontainers and @ServiceConnection.
DesignIntermediate7 min read
Your suite has 120 test classes each starting its own PostgreSQL and Kafka containers. How would you cut the time without making tests depend on each other?
LeadershipAdvanced6 min read
Should integration tests in your organisation use Testcontainers, shared test environments, or both? Give your reasoning.
LeadershipPrincipal8 min read
Testcontainers makes it easy to run real infrastructure in tests. Over years, what costs and risks come with depending on it across thousands of builds, and how do you manage them?

Database tests

ConceptFoundations8 min read
Why can a repository test pass on H2 but fail on PostgreSQL in production?
DebuggingFoundations7 min read
A @DataJpaTest saves an entity that violates a unique constraint, but the test that expects an exception fails because nothing is thrown. Why?
DebuggingIntermediate7 min read
A @SpringBootTest with webEnvironment = RANDOM_PORT is annotated @Transactional, yet rows created via HTTP calls are not rolled back. Why?
LeadershipAdvanced7 min read
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?

Test data management

ConceptFoundations6 min read
Compare @Sql scripts, test data builders and the Object Mother pattern for setting up data in Spring tests.
DesignIntermediate7 min read
Design a test data strategy for integration tests that run in parallel against one shared database container.
ScenarioAdvanced7 min read
Teams copy anonymised production data into test environments, but privacy reviewers now object. What alternatives would you propose?
ScenarioPrincipal7 min read
Regulators require that no personal data appears in non-production systems, but your integration tests and staging environments have used production copies for a decade. How would you plan the exit?

Flaky tests

DebuggingFoundations7 min read
An asynchronous test sometimes fails because a message listener has not processed the event yet. The test uses Thread.sleep(500). How would you fix it?
ScenarioIntermediate8 min read
About 3 percent of CI builds fail on random tests that pass on retry. How do you investigate and reduce flakiness?
LeadershipPrincipal6 min read
Over years, how do flaky tests affect an engineering organisation, and what policies would you put in place?

HTTP service mocking with WireMock and MockWebServer

CodingFoundations7 min read
Write a Spring Boot test that stubs a downstream GET /customers/42 returning JSON with WireMock, and points the application's RestClient at the stub. How do you verify the request was sent with the right header?
ScenarioIntermediate7 min read
Integration tests use WireMock stubs written by hand, and production failed because the real downstream API changed a field name. How do you keep HTTP mocks honest, and how do you test timeouts and retries?
DesignAdvanced7 min read
Across 150 services, teams mock dependencies differently: some call shared staging environments, some use WireMock, some mock HTTP clients in unit tests. What testing standard would you set for service-to-service calls?

REST API testing with REST Assured

CodingFoundations7 min read
Write a REST Assured test against a Spring Boot app started with webEnvironment = RANDOM_PORT that posts a JSON order and checks status 201, a Location header and the id in the body.
ConceptIntermediate7 min read
Compare REST Assured, MockMvc, WebTestClient and the newer RestTestClient or MockMvcTester options in Spring for testing REST APIs. When would you pick each?
ScenarioAdvanced7 min read
Your API test suite of 2,000 REST Assured tests takes 50 minutes and runs against a shared environment. Releases wait for it. How would you restructure API testing?