Integration tests that don't lie
TestContainers strategies to keep CI/CD fast without losing confidence in your code.
Author: Danilo FernandoPublished on January 18, 2025
Green suites, fragile code
A green suite without confidence is worse than no suite — it gives you license to ship while the system burns.
The pattern that works
- TestContainers for real dependencies (Postgres, Kafka, Redis).
- Deterministic fixtures — no
@Sql+ random. - One seed per test, no shared state.
- Assert on data, not on mock invocation counts.
@Testcontainers
@SpringBootTest
class OrderConfirmationIT {
@Container
static PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres:16")
.withInitScript("db/init.sql");
@DynamicPropertySource
static void props(DynamicPropertyRegistry reg) {
reg.add("spring.datasource.url", db::getJdbcUrl);
}
}
What that buys
- Tests that turn green with the code, not after.
- Fearless refactors.
- Objective conversations at code review.
#testing #spring-boot #testcontainers