WireMock and Groovy

WARNING: This document is for an old WireMock 2.x baseline. See the documentation for the current WireMock 3.x baseline here

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 #