WireMock and Groovy
Disclaimer: This solution page includes resources maintained by their authors outside the WireMock organization on GitHub. The info is provided as is without guarantees unless explicitly specified. Referenced projects and guidelines might be incompatible with the recent WireMock 3.x releases or the recent versions of the target technology or framework.
Please use with caution, and submit GitHub issues or pull requests to this page and referenced repositories if something is missing, broken or needs update.
DSL Bindings #
There is a Groovy DSL binding library that allows to manage the WireMock JUnit rule via declarative Spock-alike definitions. Note that this library is maintained outside the WireMock organization on GitHub, and likely to be obsolete.
@Rule
WireMockRule wireMockRule = new WireMockRule()
def wireMockStub = new WireMockGroovy()
def "example verifying test" () {
...
then:
1 == wireMockStub.count {
method "GET"
url "/some/url"
}
}
def "test using groovy truth if you need at least one request and shows example matcher" () {
...
then:
wireMockStub.count {
method "POST"
url "/some/url"
headers {
"Content-Type" {
matches ".*xml"
}
}
}
}
Useful pages #
- WireMock on Java and JVM - Most of JVM generic solutions are applicable to Groovy development too