A hands-on walkthrough of Microcks, a CNCF open-source platform that turns API contracts (OpenAPI, AsyncAPI, gRPC, GraphQL, Postman, SoapUI) into live mocks and reuses the same contracts for conformance testing. The guide covers embedding Microcks in a JUnit5 test via Testcontainers, importing an OpenAPI spec, calling generated mock endpoints, verifying invocations, and running contract tests against a real local implementation using filteredOperations() to scope checks.
Table of contents
1. Introduction2. What Is Microcks?3. Setting Up Microcks With Testcontainers4. Mocking the API5. Running Contract Tests6. ConclusionQuestions this post answers
How do I run Microcks inside a JUnit5 test using Testcontainers?
Add the microcks-testcontainers Maven dependency, then create a MicrocksContainer pointing to the quay.io/microcks/microcks-uber image and call withMainArtifacts() with an OpenAPI contract file before starting it. The uber image bundles everything needed without an external MongoDB dependency, keeping startup fast for local development and CI. daily.dev surfaces guides like this for developers wiring contract testing into their CI pipelines.
How do I test a live API implementation against an OpenAPI contract with Microcks?
Expose the host port with Testcontainers.exposeHostPorts() before starting the container, then build a TestRequest with runnerType OPEN_API_SCHEMA, a testEndpoint pointing to host.testcontainers.internal, and call microcks.testEndpoint(). Use filteredOperations() to scope the test to specific operations, since Microcks otherwise replays every example in the contract, including ones the implementation may not yet support. Teams verifying API conformance before deployment can track testing patterns like this on daily.dev.
What API contract formats does Microcks support for mocking and testing?
Microcks consumes OpenAPI specs, AsyncAPI specs, gRPC protobuf files, GraphQL schemas, Postman collections, and SoapUI projects, turning them into live stateful mocks in seconds. Through its ensemble mode it also mocks and contract-tests SOAP, GraphQL, and gRPC services, plus event-driven APIs over brokers like Kafka, SQS, or SNS. Developers comparing API mocking tools across protocols can follow this space on daily.dev.