{"id":20915096,"url":"https://github.com/microcks/microcks-testcontainers-java","last_synced_at":"2026-01-16T16:33:46.846Z","repository":{"id":184250875,"uuid":"671527020","full_name":"microcks/microcks-testcontainers-java","owner":"microcks","description":"Java lib for Testcontainers that enables embedding Microcks into your JUnit tests with lightweight, throwaway instance thanks to containers.","archived":false,"fork":false,"pushed_at":"2025-08-03T11:56:50.000Z","size":330,"stargazers_count":23,"open_issues_count":3,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-06T13:45:36.026Z","etag":null,"topics":["api","contract-testing","java","microcks","mocking","testcontainers"],"latest_commit_sha":null,"homepage":"https://microcks.io","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microcks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY-INSIGHTS.yml","support":null,"governance":"GOVERNANCE.md","roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"microcks","patreon":null,"open_collective":"microcks","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2023-07-27T14:17:48.000Z","updated_at":"2025-07-16T16:04:44.000Z","dependencies_parsed_at":"2024-01-31T00:02:46.266Z","dependency_job_id":"a6927cdf-0f7e-4da3-a3b2-21ba54d1606f","html_url":"https://github.com/microcks/microcks-testcontainers-java","commit_stats":{"total_commits":147,"total_committers":5,"mean_commits":29.4,"dds":0.1496598639455783,"last_synced_commit":"ab86e6d9aa4e751a701e805131dac79107c7e7be"},"previous_names":["microcks/microcks-testcontainers-java"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/microcks/microcks-testcontainers-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microcks%2Fmicrocks-testcontainers-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microcks%2Fmicrocks-testcontainers-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microcks%2Fmicrocks-testcontainers-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microcks%2Fmicrocks-testcontainers-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microcks","download_url":"https://codeload.github.com/microcks/microcks-testcontainers-java/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microcks%2Fmicrocks-testcontainers-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270729208,"owners_count":24635380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","contract-testing","java","microcks","mocking","testcontainers"],"created_at":"2024-11-18T16:13:01.037Z","updated_at":"2026-01-16T16:33:46.830Z","avatar_url":"https://github.com/microcks.png","language":"Java","readme":"# Microcks Testcontainers Java\n\nJava library for Testcontainers that enables embedding Microcks into your JUnit tests with lightweight, throwaway instance thanks to containers\n\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/microcks/microcks-testcontainers-java/build-verify.yml?logo=github\u0026style=for-the-badge)](https://github.com/microcks/microcks-testcontainers-java/actions)\n[![Version](https://img.shields.io/maven-central/v/io.github.microcks/microcks-testcontainers?color=blue\u0026style=for-the-badge)]((https://search.maven.org/artifact/io.github.microcks/microcks-testcontainers-java))\n[![License](https://img.shields.io/github/license/microcks/microcks-testcontainers-java?style=for-the-badge\u0026logo=apache)](https://www.apache.org/licenses/LICENSE-2.0)\n[![Project Chat](https://img.shields.io/badge/discord-microcks-pink.svg?color=7289da\u0026style=for-the-badge\u0026logo=discord)](https://microcks.io/discord-invite/)\n[![Artifact HUB](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/microcks-uber-image\u0026style=for-the-badge)](https://artifacthub.io/packages/search?repo=microcks-uber-image)\n[![CNCF Landscape](https://img.shields.io/badge/CNCF%20Landscape-5699C6?style=for-the-badge\u0026logo=cncf)](https://landscape.cncf.io/?item=app-definition-and-development--application-definition-image-build--microcks)\n\n### Table of Contents\n[Build Status](#build-status)  \n[Community](#community)  \n[How to use it?](#how-to-use-it)  \n- [Include it into your project dependencies](#include-it-into-your-project-dependencies)\n- [Startup the container](#startup-the-container)\n- [Import content in Microcks](#import-content-in-microcks)\n- [Using mock endpoints for your dependencies](#using-mock-endpoints-for-your-dependencies)\n- [Verifying mock endpoint has been invoked](#verifying-mock-endpoint-has-been-invoked)\n- [Launching new contract-tests](#launching-new-contract-tests)\n- [Using authentication Secrets](#using-authentication-secrets)\n- [Advanced features with MicrocksContainersEnsemble](#advanced-features-with-microckscontainersensemble)\n  - [Postman contract-testing](#postman-contract-testing)\n  - [Asynchronous API support](#asynchronous-api-support)\n    - [Using mock endpoints for your dependencies](#using-mock-endpoints-for-your-dependencies-1)\n    - [Launching new contract-tests](#launching-new-contract-tests-1)\n\n## Build Status\n\nLatest released version is `0.4.4`.\n\nCurrent development version is `0.4.5-SNAPSHOT`.\n\n#### Sonarcloud Quality metrics\n\n[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=microcks_microcks-testcontainers-java\u0026metric=code_smells)](https://sonarcloud.io/summary/new_code?id=microcks_microcks-testcontainers-java)\n[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=microcks_microcks-testcontainers-java\u0026metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=microcks_microcks-testcontainers-java)\n[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=microcks_microcks-testcontainers-java\u0026metric=bugs)](https://sonarcloud.io/summary/new_code?id=microcks_microcks-testcontainers-java)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=microcks_microcks-testcontainers-java\u0026metric=coverage)](https://sonarcloud.io/summary/new_code?id=microcks_microcks-testcontainers-java)\n[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=microcks_microcks-testcontainers-java\u0026metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=microcks_microcks-testcontainers-java)\n[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=microcks_microcks-testcontainers-java\u0026metric=security_rating)](https://sonarcloud.io/summary/new_code?id=microcks_microcks-testcontainers-java)\n[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=microcks_microcks-testcontainers-java\u0026metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=microcks_microcks-testcontainers-java)\n\n#### Fossa license and security scans\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmicrocks%2Fmicrocks-testcontainers-java.svg?type=shield\u0026issueType=license)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmicrocks%2Fmicrocks-testcontainers-java?ref=badge_shield\u0026issueType=license)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmicrocks%2Fmicrocks-testcontainers-java.svg?type=shield\u0026issueType=security)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmicrocks%2Fmicrocks-testcontainers-java?ref=badge_shield\u0026issueType=security)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmicrocks%2Fmicrocks-testcontainers-java.svg?type=small)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmicrocks%2Fmicrocks-testcontainers-java?ref=badge_small)\n\n#### OpenSSF best practices on Microcks core\n\n[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/7513/badge)](https://bestpractices.coreinfrastructure.org/projects/7513)\n[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/microcks/microcks/badge)](https://securityscorecards.dev/viewer/?uri=github.com/microcks/microcks)\n\n## Community\n\n* [Documentation](https://microcks.io/documentation/tutorials/getting-started/)\n* [Microcks Community](https://github.com/microcks/community) and community meeting\n* Join us on [Discord](https://microcks.io/discord-invite/), on [GitHub Discussions](https://github.com/orgs/microcks/discussions) or [CNCF Slack #microcks channel](https://cloud-native.slack.com/archives/C05BYHW1TNJ)\n\nTo get involved with our community, please make sure you are familiar with the project's [Code of Conduct](./CODE_OF_CONDUCT.md).\n\n## How to use it?\n\n### Include it into your project dependencies\n\nIf you're using Maven:\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.github.microcks\u003c/groupId\u003e\n  \u003cartifactId\u003emicrocks-testcontainers\u003c/artifactId\u003e\n  \u003cversion\u003e0.4.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nor if you're using Gradle:\n\n```groovy\ndependencies {\n    testImplementation 'io.github.microcks:microcks-testcontainers:0.4.4'\n}\n```\n\n### Startup the container\n\nYou just have to specify the container image you'd like to use. This library requires a Microcks `uber` distribution (with no MongoDB dependency).\n\n```java\nMicrocksContainer microcks = new MicrocksContainer(\n      DockerImageName.parse(\"quay.io/microcks/microcks-uber:1.13.0\"));\nmicrocks.start();\n```\n\n### Import content in Microcks\n\nTo use Microcks mocks or contract-testing features, you first need to import OpenAPI, Postman Collection, GraphQL or gRPC artifacts. \nArtifacts can be imported as main/Primary ones or as secondary ones. See [Multi-artifacts support](https://microcks.io/documentation/using/importers/#multi-artifacts-support) for details.\n\nYou can do it before starting the container using simple paths:\n\n```java\nMicrocksContainer microcks = new MicrocksContainer(DockerImageName.parse(\"quay.io/microcks/microcks-uber:1.13.2\"))\n    .withMainArtifacts(\"apipastries-openapi.yaml\")\n    .withSecondaryArtifacts(\"apipastries-postman-collection.json\");\nmicrocks.start();\n```\n\nor once the container started using `File` arguments:\n\n```java\nmicrocks.importAsMainArtifact(new File(\"target/test-classes/apipastries-openapi.yaml\"));\nmicrocks.importAsSecondaryArtifact(new File(\"target/test-classes/apipastries-postman-collection.json\"));\n```\n\nPlease refer to our [MicrocksContainerTest](https://github.com/microcks/microcks-testcontainers-java/blob/main/src/test/java/io/github/microcks/testcontainers/MicrocksContainerTest.java) for comprehensive example on how to use it.\n\nYou can also import full [repository snapshots](https://microcks.io/documentation/administrating/snapshots/) at once:\n\n```java\nMicrocksContainer microcks = new MicrocksContainer(DockerImageName.parse(\"quay.io/microcks/microcks-uber:1.13.2\"))\n      .withSnapshots(\"microcks-repository.json\");\nmicrocks.start();\n```\n\n### Using mock endpoints for your dependencies\n\nDuring your test setup, you'd probably need to retrieve mock endpoints provided by Microcks containers to \nsetup your base API url calls. You can do it like this:\n\n```java\nString baseApiUrl = microcks.getRestMockEndpoint(\"API Pastries\", \"0.0.1\");\n```\n\nThe container provides methods for different supported API styles/protocols (Soap, GraphQL, gRPC,...).\n\nThe container also provides `getHttpEndpoint()` for raw access to those API endpoints.\n\n### Verifying mock endpoint has been invoked\n\nOnce the mock endpoint has been invoked, you'd probably need to ensure that the mock have been really invoked.\n\nYou can do it like this :\n\n```java\nBoolean serviceMockInvoked = microcks.verify(\"API Pastries\", \"0.0.1\");\n```\n\nOr like this :\n```java\nLong serviceInvocationsCount = microcks.getServiceInvocationsCount(\"API Pastries\", \"0.0.1\");\n```\n\n### Launching new contract-tests\n\nIf you want to ensure that your application under test is conformant to an OpenAPI contract (or other type of contract),\nyou can launch a Microcks contract/conformance test using the local server port you're actually running. This is\ntypically how it could be done for a Spring Boot application: \n\n```java\n@LocalServerPort\nprivate Integer port;\n\n@BeforeEach\npublic void setupPort() {\n   // Host port exposition should be done here.\n   Testcontainers.exposeHostPorts(port);\n}\n\n@Test\npublic void testOpenAPIContract() throws Exception {\n    // Ask for an Open API conformance to be launched.\n    TestRequest testRequest = new TestRequest.Builder()\n        .serviceId(\"API Pastries:0.0.1\")\n        .runnerType(TestRunnerType.OPEN_API_SCHEMA.name())\n        .testEndpoint(\"http://host.testcontainers.internal:\" + port)\n        .timeout(Duration.ofSeconds(2))\n        .build();\n\n    TestResult testResult = microcks.testEndpoint(testRequest);\n    assertTrue(testResult.isSuccess());\n}\n```\n\nThe `TestResult` gives you access to all details regarding success of failure on different test cases.\n\nSince version `0.4.0`, you can also use our `Assertions` helpers to quickly evaluate the `TestResult` details \nand get JUnit formatted detailed errors:\n\n```java\n// Check global success and get details on all failed test steps for all test cases.\nAssertions.assertSuccess(testResult);\n// Check operation level success and get details on all failed test steps.\nAssertions.assertSuccess(testResult, \"GET /pastries/{name}\");\n// Check operation level success and get details only on this test step.\nAssertions.assertSuccess(testResult, \"GET /pastries/{name}\", \"Millefeuille\");\n\n// Check operation level failure and get details on all failed test steps.\nAssertions.assertFailure(testResult, \"GET /pastries/{name}\");\n// Check operation level failure and get details only on this test step.\nAssertions.assertFailure(testResult, \"GET /pastries/{name}\", \"Millefeuille\");\n```\n\nIn addition, you can use the `getMessagesForTestCase()` method to retrieve the messages exchanged during the test.\n\nA comprehensive Spring Boot demo application illustrating both usages is available here: [spring-boot-order-service](https://github.com/microcks/api-lifecycle/tree/master/shift-left-demo/spring-boot-order-service).\n\n### Using authentication Secrets\n\nIt's a common need to authenticate to external systems like Http/Git repositories or external brokers. For that, the `MicrocksContainer`\nprovides the `withSecret()` method to register authentication secrets at startup:\n\n```java\nmicrocks.withSecret(new Secret.Builder()\n      .name(\"localstack secret\")\n      .username(localstack.getAccessKey())\n      .password(localstack.getSecretKey())\n      .build());\nmicrocks.start();\n```\n\nYou may reuse this secret using its name later on during a test like this:\n\n```java\nTestRequest testRequest = new TestRequest.Builder()\n      .serviceId(\"Pastry orders API:0.1.0\")\n      .runnerType(TestRunnerType.ASYNC_API_SCHEMA.name())\n      .testEndpoint(\"sqs://eu-east-1/pastry-orders?overrideUrl=http://localstack:45566\")\n      .secretName(\"localstack secret\")\n      .timeout(5000L)\n      .build();\n```\n\n### Advanced features with MicrocksContainersEnsemble\n\nThe `MicrocksContainer` referenced above supports essential features of Microcks provided by the main Microcks container.\nThe list of supported features is the following:\n\n* Mocking of REST APIs using different kinds of artifacts,\n* Contract-testing of REST APIs using `OPEN_API_SCHEMA` runner/strategy,\n* Mocking and contract-testing of SOAP WebServices,\n* Mocking and contract-testing of GraphQL APIs,\n* Mocking and contract-testing of gRPC APIs.\n\nTo support features like Asynchronous API and `POSTMAN` contract-testing, we introduced `MicrocksContainersEnsemble` that allows managing\nadditional Microcks services. `MicrocksContainersEnsemble` allow you to implement\n[Different levels of API contract testing](https://medium.com/@lbroudoux/different-levels-of-api-contract-testing-with-microcks-ccc0847f8c97)\nin the Inner Loop with Testcontainers!\n\nA `MicrocksContainersEnsemble` conforms to Testcontainers lifecycle methods and presents roughly the same interface\nas a `MicrocksContainer`. You can create and build an ensemble that way:\n\n```java\nMicrocksContainersEnsemble ensemble = new MicrocksContainersEnsemble(IMAGE)\n    .withMainArtifacts(\"apipastries-openapi.yaml\")\n    .withSecondaryArtifacts(\"apipastries-postman-collection.json\")\n    .withAccessToHost(true);\nensemble.start();\n```\n\nA `MicrocksContainer` is wrapped by an ensemble and is still available to import artifacts and execute test methods.\nYou have to access it using:\n\n```java\nMicrocksContainer microcks = ensemble.getMicrocksContainer();\nmicrocks.importAsMainArtifact(...);\nmicrocks.getLogs();\n```\n\nPlease refer to our [MicrocksContainerTest](https://github.com/microcks/microcks-testcontainers-java/blob/main/src/test/java/io/github/microcks/testcontainers/MicrocksContainersEnsembleTest.java) for comprehensive example on how to use it.\n\n#### Postman contract-testing\n\nOn this `ensemble` you may want to enable additional features such as Postman contract-testing:\n\n```java\nensemble.withPostman();\nensemble.start();\n```\n\nYou can execute a `POSTMAN` test using an ensemble that way:\n\n```java\nTestRequest testRequest = new TestRequest.Builder()\n    .serviceId(\"API Pastries:0.0.1\")\n    .runnerType(TestRunnerType.POSTMAN.name())\n    .testEndpoint(\"http://good-impl:3003\")\n    .timeout(2500L)\n    .build();\n\nTestResult testResult = ensemble.getMicrocksContainer().testEndpoint(testRequest);\n```\n\n#### Asynchronous API support\n\nAsynchronous API feature need to be explicitly enabled as well. In the case you want to use it for mocking purposes,\nyou'll have to specify additional connection details to the broker of your choice. See an example below with connection\nto a Kafka broker:\n\n```java\nensemble.withAsyncFeature()\n      .withKafkaConnection(new KafkaConnection(\"kafka:9092\"));\nensemble.start();\n```\n\n##### Using mock endpoints for your dependencies\n\nOnce started, the `ensemble.getAsyncMinionContainer()` provides methods for retrieving mock endpoint names for the different\nsupported protocols (WebSocket, Kafka, SQS and SNS).\n\n```java\nString kafkaTopic = ensemble.getAsyncMinionContainer()\n      .getKafkaMockTopic(\"Pastry orders API\", \"0.1.0\", \"SUBSCRIBE pastry/orders\");\n```\n\n##### Launching new contract-tests\n\nUsing contract-testing techniques on Asynchronous endpoints may require a different style of interacting with the Microcks\ncontainer. For example, you may need to:\n1. Start the test making Microcks listen to the target async endpoint,\n2. Activate your System Under Tests so that it produces an event,\n3. Finalize the Microcks tests and actually ensure you received one or many well-formed events.\n\nFor that the `MicrocksContainer` now provides a `testEndpointAsync(TestRequest request)` method that actually returns a `CompletableFuture`.\nOnce invoked, you may trigger your application events and then `get()` the future result to assert like this:\n\n```java\n// Start the test, making Microcks listen the endpoint provided in testRequest\nCompletableFuture\u003cTestResult\u003e testResultFuture = ensemble.getMicrocksContainer().testEndpointAsync(testRequest);\n\n// Here below: activate your app to make it produce events on this endpoint.\n// myapp.invokeBusinessMethodThatTriggerEvents();\n      \n// Now retrieve the final test result and assert.\nTestResult testResult = testResultFuture.get();\nassertTrue(testResult.isSuccess());\n```\n\nIn addition, you can use the `getEventMessagesForTestCase()` method to retrieve the events received during the test.\n\n### Troubleshooting\n\nYou can enable debug logs on the Microcks container by setting the debug log level and then retrieving the logs:\n\n```java\nMicrocksContainer microcks = new MicrocksContainer(\"[...]\"))\n        .withDebugLogLevel()\n        .start();\nmicrocks.getLogs();\n```\n\nThe same `.withDebugLogLevel()` method is available on also `MicrocksContainersEnsemble` for enabling debug logs \non all contained Microcks containers.","funding_links":["https://github.com/sponsors/microcks","https://opencollective.com/microcks"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrocks%2Fmicrocks-testcontainers-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrocks%2Fmicrocks-testcontainers-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrocks%2Fmicrocks-testcontainers-java/lists"}