{"id":23035863,"url":"https://github.com/abedurftig/gradle-integration-tests","last_synced_at":"2026-04-14T15:32:37.605Z","repository":{"id":81329178,"uuid":"269363624","full_name":"abedurftig/gradle-integration-tests","owner":"abedurftig","description":"Run Unit tests first, then Integration tests (which also use WireMock)","archived":false,"fork":false,"pushed_at":"2020-06-06T11:25:53.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T22:42:04.973Z","etag":null,"topics":["docker-compose","gradle","jvm","kotlin","learning","testing","wiremock"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abedurftig.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-04T13:13:18.000Z","updated_at":"2020-06-06T11:25:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"d7a607a0-becf-47a1-8cd4-9f415ccddb0a","html_url":"https://github.com/abedurftig/gradle-integration-tests","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/abedurftig/gradle-integration-tests","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abedurftig%2Fgradle-integration-tests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abedurftig%2Fgradle-integration-tests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abedurftig%2Fgradle-integration-tests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abedurftig%2Fgradle-integration-tests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abedurftig","download_url":"https://codeload.github.com/abedurftig/gradle-integration-tests/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abedurftig%2Fgradle-integration-tests/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31803310,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T11:13:53.975Z","status":"ssl_error","status_checked_at":"2026-04-14T11:13:53.299Z","response_time":153,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["docker-compose","gradle","jvm","kotlin","learning","testing","wiremock"],"created_at":"2024-12-15T16:47:15.450Z","updated_at":"2026-04-14T15:32:37.587Z","avatar_url":"https://github.com/abedurftig.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Kotlin \u0026 Gradle project which runs Integration tests only after Unit tests passed\n\n## Summary\n\nA Gradle project which runs `Integration tests` after `Unit tests` (only if they pass). Before running the `Integration tests`, `Gradle` brings up `Docker` containers using `Docker Compose`. After the `Integration tests` finish stop the `Docker` containers.\n\n## Goals\n\nLearn how to:\n\n- Separate Unit tests from Integration tests to fail fast\n- Use [WireMock](http://wiremock.org/) during `Integration tests`\n- Leverage Docker Compose to bring up external dependencies during the `Integration test` phase\n\n### Separate Unit tests from Integration tests\n\nWhile most blog posts and articles are suggesting to use a separate `sourceSet`, this example\nleverages a naming pattern for the test classes which should be run as part of the `Integration tests`.\n\nThe Gradle `test` task excludes all test classes with the following pattern `\"**/*Integration*\"`.\n\n```kotlin\ntest {\n    exclude(\"**/*Integration*\")\n}\n```\n\nA new task of type `Test` and with name `integrationTest` has been added. It uses the same\ntest classes directory and classpath as the `test` task. It specifically includes the test classes,\nwhich have been excluded in the `test` task. It should run after the `test` task.\n\n```kotlin\ntask\u003cTest\u003e(\"integrationTest\") {\n    description = \"Runs integration tests.\"\n    group = \"verification\"\n    testClassesDirs = sourceSets.test.get().output.classesDirs\n    classpath = sourceSets.test.get().runtimeClasspath\n\n    include(\"**/*Integration*\")\n    shouldRunAfter(\"test\")\n}\n```\nThis project uses JUnit5. Both tasks should use the Junit platform aka. JUnit5.\n\n```kotlin\ntasks.withType(Test::class.java) {\n    useJUnitPlatform()\n}\n```\nThe last step is to include the `integrationTest` task as part of the `check` task.\n\n```kotlin\ncheck {\n    dependsOn(\"integrationTest\")\n}\n```\n\n#### How to test that it works\n\nIn the `ExternalServiceConsumerTest` class just comment in the following line before running `./gradlew check`.\n\n```kotlin\n// Assertions.fail\u003cAny\u003e(\"Just because\")\n```\nThe `test` task fails and the build does not execute the `integrationTest` task. ✅\n\n### Use WireMock for during Integration tests\n\nWireMock is a mock API server. There are different ways to use it and to define the mock endpoints and responses. Since we want to bring up the mock server with `Docker Compose\n`, I define the mocks in JSON files. See the `wiremock` folder and in there the `sample-mock-endpoint.json`.\n\nIn the `docker-compose.yml` I use a WireMock Docker image and map the `wiremock` folder\nto the container.\n\nAfter you run `docker-compose up`, you can request `GET http://localhost:9999/some/thing`. ✅\n\n### Bring up external dependencies during Integration tests\n\nI use a [Gradle plugin](https://github.com/avast/gradle-docker-compose-plugin) to integrate Docker Compose into the Gradle build. The `integrationTest` task has been modified to\n run `docker-compose up` before and `docker-compose down` after the tests.\n \n```kotlin\ntask\u003cTest\u003e(\"integrationTest\") {\n    description = \"Runs integration tests.\"\n    ...\n    dependsOn(\"composeUp\")\n    finalizedBy(\"composeDown\")\n}\n``` \nSee the logs of the [Build and Test](https://github.com/abedurftig/gradle-integration-tests/runs/743499035?check_suite_focus=true) step of the related GitHub Actions workflow. ✅\n\n## Final thoughts\n\nIt was a lot easier than I thought. WireMock seems like a great tool\nwhich can help to simulate different API scenarios. Even those, which might be rather rare. Thinking of long response times for example. Using the JSON format and running\nWireMock in a Docker container makes the setup fairly straight forward.\n\nPlus obviously we can bring up more than just the API dependency. Also databases like Postgres or Redis for example.\n \nI don't see the benefit of using multiple `sourceSets`. Filtering the tests by matching a pattern in the classname seems like an easy approach.\n \nFor this example I have chosen a multi-module setup (with a single module) and the `BuildSrc` folder, so there are a few open questions.\n\n- How would it work if I had `Integration tests` in more than one module? Would the WireMock container have to go up and down multiple times?\n- What about test coverage reports? How does that work when I have multiple tests tasks? I already noticed in a different project, that Jacoco together with `Console Reporter\n` plugin don't work reliably.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabedurftig%2Fgradle-integration-tests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabedurftig%2Fgradle-integration-tests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabedurftig%2Fgradle-integration-tests/lists"}