integration-tests

Test Spring Boot services against real databases, brokers, and HTTP dependencies using Testcontainers and WireMock.

Updated Jun 25, 2026
One-click install
npx skills add https://github.com/oriddd/ai-toolkit --skill integration-tests-oriddd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: integration-tests
Source: https://github.com/oriddd/ai-toolkit/tree/main/copilot/public/skills/integration-tests
Command: npx skills add https://github.com/oriddd/ai-toolkit --skill integration-tests-oriddd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Component tests with in-process fakes cannot verify behaviour that depends on the real semantics of downstream systems like PostgreSQL, Kafka, or S3. This Skill shows how to drive a Spring Boot microservice against real dependencies with Testcontainers and WireMock, while keeping the fast unit/component test loop intact through strict Surefire/Failsafe segregation. ## Core Features & Use Cases - Testcontainers integration: Spin up real PostgreSQL, MySQL, MongoDB, Kafka, RabbitMQ, MinIO, or LocalStack containers in tests, wiring connection details via @DynamicPropertySource. - Surefire/Failsafe split: Keep *Test.java fast in Surefire and isolate slow *IT.java integration tests in Failsafe with @Tag("integration"), so mvn test stays fast and mvn verify runs the full suite. - WireMock HTTP stubs and contract testing: Stub HTTP downstreams with WireMock (including record/replay), and adopt either Spring Cloud Contract or Pact for producer/consumer contract verification. - Use Case: A repository query behaves differently on H2 than on production PostgreSQL. Write a FooRepositoryIT with a PostgreSQLContainer so the test runs against the real database engine in CI before merge. ## Quick Start Ask the AI to apply the integration-tests skill to add a Testcontainers-based integration test for a repository or client class in the current Spring Boot project.

Frequently Asked Questions about integration-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write integration tests with Testcontainers in Spring Boot?

Annotate the test class with @SpringBootTest, @Testcontainers, and @Tag("integration"), declare a static container such as PostgreSQLContainer with @Container, and inject its JDBC URL and credentials through @DynamicPropertySource. Name the class *IT.java so Failsafe runs it.

What is the difference between Surefire and Failsafe in Maven?

Surefire runs **/*Test.java (unit and component tests) during mvn test, keeping the inner loop fast. Failsafe runs **/*IT.java during mvn verify, which suits slow integration tests that need Docker containers.

Should I use Pact or Spring Cloud Contract for contract testing?

Pick exactly one per organization. Spring Cloud Contract uses a Groovy DSL and is JVM-only, publishing a stubs jar consumers load via @AutoConfigureStubRunner. Pact is polyglot and uses a Pact Broker where the producer verifies consumer expectations on every build.

Can I use H2 or embedded Kafka instead of Testcontainers?

No. Embedded H2 and embedded Kafka do not reproduce the real semantics of the downstream system, so tests can pass while production fails. Use Testcontainers with the real database or broker image for any test whose behaviour depends on the downstream.

Why is my Testcontainers test failing to connect to the database?

A common cause is assuming a fixed host port instead of reading the mapped port from the container. Always wire connection properties through @DynamicPropertySource using container methods like getJdbcUrl, and ensure Docker is running when Failsafe executes.

How do I speed up Testcontainers tests locally?

Enable container reuse with .withReuse(true) on the container and testcontainers.reuse.enable=true in ~/.testcontainers.properties. Also keep one container per test class where possible and never run integration tests during mvn test.