---
title: "Model-Based Testing with Testcontainers and Jqwik"
description: "Model-based testing can regression-test a REST API by running the current version (Postgres-backed) and a candidate version (MySQL-backed) side by side, sending both identical randomly generated request sequences, and comparing their responses."
url: "https://swe.quest/articles/model-based-testing-with-testcontainers-and-jqwik-e941a47b3c07d6eb"
canonical: "https://www.docker.com/blog/model-based-testing-testcontainers-jqwik/"
source: "Docker"
published: "2024-10-23"
difficulty: "medium"
kind: "How-to"
reading_minutes: 6
tags: ["testing","jvm","containers"]
---

# Model-Based Testing with Testcontainers and Jqwik

A post on [Docker](https://swe.quest/sources/docker.md), published 2024-10-23, 6 min read, How-to. Original: [https://www.docker.com/blog/model-based-testing-testcontainers-jqwik/](https://www.docker.com/blog/model-based-testing-testcontainers-jqwik/)

## Summary

Model-based testing can regression-test a REST API by running the current version (Postgres-backed) and a candidate version (MySQL-backed) side by side, sending both identical randomly generated request sequences, and comparing their responses. Testcontainers' ComposeContainer starts both apps and their databases from a Docker Compose file. jqwik's Arbitraries and ActionSequence generate sequences of CRUD actions that assert matching status codes and bodies. In the demo, the generated tests quickly find a divergence on a department search with unusual Unicode input, traced to a Postgres-specific native SQL query.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)
- [Java & JVM](https://swe.quest/tags/jvm.md) (Languages)
- [Containers](https://swe.quest/tags/containers.md) (Infrastructure)

## Prerequisites

- JUnit 5
- Docker Compose ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))
- Java REST APIs ([easy posts on Java & JVM](https://swe.quest/tags/jvm.md?difficulty=easy))

## Keywords

Testcontainers, jqwik, JUnit 5, Docker Compose, model-based testing, property-based testing

## Related posts

- [Functional tests with Testcontainers](https://swe.quest/articles/functional-tests-with-testcontainers-8e8bddfb01d0b1bc.md): Zalando Engineering · 2022-04-11 · Medium · 7 min read · Testing, Java & JVM, Containers
  Black-box functional tests for a Spring service can run against the service packaged as a Docker image, with PostgreSQL and other dependencies started as separate containers via Testcontainers.
- [Leveraging Testcontainers for Complex Integration Testing in Mattermost Plugins](https://swe.quest/articles/leveraging-testcontainers-for-complex-integration-testing-in-mattermost-plugins-3edaea4757026529.md): Docker · 2024-10-08 · Medium · 6 min read · Testing, Containers, Go, JavaScript
  Mattermost replaced brittle mock-based plugin tests with Testcontainers-driven integration tests that spin up a Mattermost server, PostgreSQL on an internal Docker network, and optional API mock containers.
- [Test Your Database Without Mocks](https://swe.quest/articles/test-your-database-without-mocks-093131d18e46824a.md): Neon · 2025-01-15 · Medium · 7 min read · Testing, PostgreSQL, CI/CD
  Database mocks are brittle, expensive to maintain, and test little beyond the mock itself, since they skip real behaviour like transactions, isolation levels, foreign keys and referential integrity.
- [Shift-Left Testing with Testcontainers: Catching Bugs Early with Local Integration Tests](https://swe.quest/articles/shift-left-testing-with-testcontainers-catching-bugs-early-with-local-f90241b596ffcd90.md): Docker · 2025-03-13 · Medium · 10 min read · Testing, Developer productivity, PostgreSQL, TypeScript
  Running integration tests locally against real dependencies via Testcontainers catches bugs that unit tests and mocks miss, before code reaches shared CI or staging environments.
- [AI-Powered Testing: Using Docker Model Runner with Microcks for Dynamic Mock APIs](https://swe.quest/articles/ai-powered-testing-using-docker-model-runner-with-microcks-for-dynamic-mock-apis-5407790a30e64f9c.md): Docker · 2025-07-14 · Medium · 4 min read · Testing, LLMs, Containers, Developer tools
  Microcks' AI Copilot can generate varied, realistic mock API responses using a local LLM served by Docker Model Runner through its OpenAI-compatible endpoint.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
