{"id":20086288,"url":"https://github.com/asarkar/mockserver-spring","last_synced_at":"2025-10-17T19:40:06.763Z","repository":{"id":53350601,"uuid":"312598740","full_name":"asarkar/mockserver-spring","owner":"asarkar","description":null,"archived":false,"fork":false,"pushed_at":"2021-06-12T01:12:48.000Z","size":74,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T02:18:39.244Z","etag":null,"topics":["annotation","integration-testing","mockserver","spring","spring-boot","testing"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/asarkar.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}},"created_at":"2020-11-13T14:31:58.000Z","updated_at":"2023-01-02T18:51:28.000Z","dependencies_parsed_at":"2022-09-05T01:10:11.776Z","dependency_job_id":null,"html_url":"https://github.com/asarkar/mockserver-spring","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asarkar%2Fmockserver-spring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asarkar%2Fmockserver-spring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asarkar%2Fmockserver-spring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asarkar%2Fmockserver-spring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asarkar","download_url":"https://codeload.github.com/asarkar/mockserver-spring/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241518781,"owners_count":19975542,"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","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":["annotation","integration-testing","mockserver","spring","spring-boot","testing"],"created_at":"2024-11-13T16:01:03.203Z","updated_at":"2025-10-17T19:40:06.691Z","avatar_url":"https://github.com/asarkar.png","language":"Kotlin","readme":"# mockserver-spring\n\nStarts a `MockServer` and makes the port available as Spring Boot environment property. Stops the server when the Spring\ncontext is destroyed.\n\nRequires Java 8 or later. Uses [mockserver](https://github.com/mock-server/mockserver)\nand [Spring Boot](https://spring.io/projects/spring-boot).\n\n## Installation\n\nYou can find the latest version\non [Maven Central](https://search.maven.org/search?q=g:com.asarkar.spring%20AND%20a:mockserver-spring).\n\n## Usage\n\nThe only thing you need is the `AutoConfigureMockServer` annotation:\n\n```\n@SpringBootTest\n@AutoConfigureMockServer\npublic class AutoConfigureWithKnownPortsTest {\n    @BeforeEach\n    // create expectation using port 1080\n\n    @Test\n    public void testConnection() {\n        // GET \"http://localhost:1080/\"\n    }\n}\n```\n\nTo use random port:\n\n```\n@SpringBootTest\n@AutoConfigureMockServer(port = 0)\npublic class AutoConfigureWithRandomPortsTest {\n    @Value(\"${mockserver.port:-1}\")\n    private int port;\n\n    @BeforeEach\n    // create expectation using port\n\n    @Test\n    public void testConnection() {\n        // GET \"http://localhost:port/\"\n    }\n}\n```\n\nIf you want to configure the `MockServer` before it's started, provide an implementation for\n[MockServerConfigurationProvider](src/main/kotlin/com/asarkar/spring/test/mockserver/MockServerConfigurationProvider.kt)\n, as a Spring bean.\n\nSee KDoc for more details.\n\n### Gotchas\n\n1. Do not create expectations in the static `beforeAll()` method; it runs before the MockServer starts. If you want to\n   create commons expectations, either do it in the `beforeEach()` method, which runs before each test method, or do it\n   in a non static `beforeAll()` method. In the second case, you'll have to also annotate your test class with\n   `@TestInstance(Lifecycle.PER_CLASS)`.\n\n2. In order for the server to be started, the class given to `@SpringBootTest` must be annotated with\n   `@SpringBootApplication`. Such a class can be specified in the `classes` attribute of `@SpringBootTest` annotation,\n   or found implicitly by component scan.\n\n## Contribute\n\nThis project is a volunteer effort. You are welcome to send pull requests, ask questions, or create issues. If you like\nit, you can help by spreading the word and \"Starring\" the GitHub repo!\n\n## License\n\nCopyright 2021 Abhijit Sarkar - Released under [Apache License v2.0](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasarkar%2Fmockserver-spring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasarkar%2Fmockserver-spring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasarkar%2Fmockserver-spring/lists"}