Project | Web & API

Integration Testing with Testcontainers (Kafka, GraphQL)

An event-driven order service tested through its GraphQL API and Kafka topics: migrations on the real database, schema and validation errors, published events, idempotent consumption, retries and dead-letter handling, plus mutation checks of the tests themselves.

Every run starts real PostgreSQL and Kafka in Docker; the tests prove duplicate events are applied once and broken events reach the dead-letter topic without blocking the partition, with no sleeps anywhere.

Evidence checked 17 Oct 2026 | CI run on main

GitHub Actions workflow badge
On this page
  1. Problem and purpose
  2. Architecture
  3. Technology and tools
  4. Engineering decisions and approach
  5. Test scope and execution approach
  6. Results with dated evidence
  7. Evidence explorer
  8. Local setup and execution
  9. Workflow and reports
  10. Known limitations

Problem and purpose

Between unit tests and end-to-end tests sits the layer where many production bugs live: a migration that fails on the real database, an event with a wrong field, a consumer that stalls on one bad message. This project tests exactly that layer, with real infrastructure per run instead of mocks, an in-memory database or a shared test environment.

Architecture

test ──GraphQL/HTTP──► order service ──► PostgreSQL 18 (container)
                          │  ▲
          orders.placed ◄─┘  └── payments.completed ◄── test (KafkaTemplate)
                                    │ failures
                                    ▼
                          payments.completed.DLT ──► test probe

Technology and tools

AreaTools
ServiceJava 21, Spring Boot 4.1: GraphQL API, Spring Data JDBC on PostgreSQL with Flyway, Spring Kafka
ContainersTestcontainers 2 with @ServiceConnection: postgres:18-alpine and apache/kafka-native:4.1.1, pinned, started once per run
TestsJUnit 5, HttpGraphQlTester over real HTTP, a topic probe outside any consumer group, Awaitility instead of sleeps
CIGitHub Actions on the Ubuntu runner with Docker; a table of test classes and times in the job summary

Engineering decisions and approach

  • Real PostgreSQL and Kafka, because H2 and mocked brokers hide exactly what breaks: SQL dialect, constraints, partitions, redelivery
  • One cached Spring context for every test class, so the containers start once per run
  • Unique data per test instead of cleanup: no order dependence, ready for parallel runs
  • Awaitility polls for the expected state; absence is proven by waiting for a later event on the same partition
  • Idempotent consumer: event id recorded in the same transaction as the change

Test scope and execution approach

Project-specific checks and execution details documented in the repository:

  • Migrations and check constraints tested on the real database
  • GraphQL: queries, the mutation, BAD_REQUEST validation errors, schema rejections, null propagation
  • Events: OrderPlaced published after commit and keyed by order id; duplicates applied once; broken, incomplete and unknown-order events dead-lettered without blocking
  • Found that Spring Kafka 4 renamed the default dead-letter topic; the name is now explicit
  • A mutation check revealed an untested retry rule; a unit test now covers it
  • Design notes and 60 interview questions on integration testing, Kafka and GraphQL (Markdown + PDF)

Results with dated evidence

Historical repository or workflow evidence · older evidence; recheck the linked source

CI run on main

Every run starts real PostgreSQL and Kafka in Docker; the tests prove duplicate events are applied once and broken events reach the dead-letter topic without blocking the partition, with no sleeps anywhere.

Evidence checked: | Open dated evidence

Evidence explorer

Static screenshots are labelled as images; dated workflow links identify the execution evidence and its check date.

Test report screenshot. What each test class proves, and the event-handling cases the tests pin down. Static image; capture date is not recorded in the portfolio data.
Overview of the integration tests

Test report screenshot. What each test class proves, and the event-handling cases the tests pin down. Static image; capture date is not recorded in the portfolio data.

Static material from the public repository. The linked verification record was checked 2026-10-17; that date is not a screenshot capture date.

Dated workflow record

Evidence checked 2026-10-17. Open CI run on main

Local setup and execution

mvnw.cmd verify                 :: 21 tests with real containers (Docker needed)
mvnw.cmd spring-boot:test-run   :: the service with the same containers, GraphiQL at /graphiql

Workflow and reports

View workflow definition.

Known limitations

  • OrderPlaced is sent after the commit; a crash in between would lose it (production would use a transactional outbox)
  • One service: contracts between producer and consumer teams are shown in the Pact project
  • The evidence is limited to the public repository and linked run; it does not establish customer production impact.

Back to Projects