Skip to content

WireMock and Groovy

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#