Luca Brunner·
WireMock stubs plus a seeded test DB - my integration suite went from zero to green
Design and implement integration tests for service interactions, database layers, and external API integrations with test container setup.
Integration Test Architect
You are a senior QA engineer specializing in integration testing. Design a complete integration test suite for the following service.
**Service Under Test:**
{{service_description}}
**Source Code:**
```
{{source_code}}
```
**External Dependencies:**
{{external_dependencies}}
**Tech Stack:**
{{tech_stack}}
**Database Schema:**
{{database_schema}}
Create:
1. **Test Strategy**: Which integration points to test and why
2. **Test Container Configuration**: Docker Compose or Testcontainers setup for all dependencies
3. **Database Setup**: Seed data scripts and migration rollback strategy
4. **API Integration Tests**: Complete tests for each endpoint with realistic request/response cycles
5. **Database Integration Tests**: Repository/DAO layer tests with actual transactions
6. **External Service Mock Tests**: WireMock or equivalent setup for 3rd party APIs
7. **Event/Message Tests**: If using queues/events, test publish/consume cycles
8. **Cleanup Strategy**: Ensure tests are isolated and idempotent
9. **CI-ready Configuration**: How to run these in a CI pipeline
Output working code for all components. Prioritize test isolation and realistic data.
Ergebnisse
Integration suite for `PaymentService` (Spring Boot, Postgres, calls the Stripe API) using Testcontainers + WireMock. Each test is isolated and CI-ready.
```java
@SpringBootTest
@Testcontainers
class PaymentServiceIT {
@Container
static PostgreSQLContainer<?> db =
new PostgreSQLContainer<>("postgres:16-alpine").withReuse(true);
@RegisterExtension
static WireMockExtension stripe =
WireMockExtension.newInstance().options(wireMockConfig().port(9090)).build();
@DynamicPropertySource
static void props(DynamicPropertyRegistry r) {
r.add("spring.datasource.url", db::getJdbcUrl);
r.add("stripe.base-url", () -> "http://localhost:9090");
}
@Test
void charge_persistsPaymentAndCallsStripe() {
stripe.stubFor(post("/v1/charges")
.willReturn(okJson("{\"id\":\"ch_1\",\"status\":\"succeeded\"}")));
var receipt = paymentService.charge(seedOrder(amount = 4999));
assertThat(receipt.status()).isEqualTo("succeeded");
// DB assertion — state actually changed
assertThat(jdbc.queryForObject(
"SELECT status FROM payments WHERE id=?", String.class, receipt.id()))
.isEqualTo("captured");
}
}
```
**Isolation:** Flyway migrates the container on startup; `@Transactional` rolls back each test. **Error tests** stub WireMock to return `503` and assert the circuit breaker opens. Runs in CI with `mvn verify` — Testcontainers pulls images via the Docker-in-Docker runner.
Modell: Claude Sonnet 4
16 Likes6 SavesScore: 15
1 Kommentar
Jonas Weber·
Sending this debugging, testing one to my whole team.