Hi all, I’m facing an issue with WireMock hanging ...
# help
t
Hi all, I’m facing an issue with WireMock hanging after the first test case and would love your assistance. In my test, I configure WireMock in a base class, which other tests later extend. The initialization looks like this:
Copy code
protected static WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort());

@BeforeAll
public static void startWireMock() {
    wireMockServer.start();
}

@AfterAll
public static void stopWireMock() {
    wireMockServer.stop();
}
Then, in my test, I extend the base class and, in the
beforeEach
stage, I configure the stubs like this:
Copy code
wireMockServer.stubFor(<http://WireMock.post|WireMock.post>(WireMock.urlPathEqualTo("/dummySuccess"))
        .willReturn(aResponse()
                .withStatus(200)));
In the first test case, everything works as expected. However, in the subsequent test cases, WireMock just hangs, and the tests fail due to a timeout that I’ve configured. I’m using wiremock-standalone v3.6.0 in my pom.xml file Is there any workaround to this? (I’ve tried calling wireMockServer.resetAll(); with no success) Thanks!
b
Which test framework are you using? JUnit 4 / 5 or TestNG?
And why would you want to recreate the same mock every time for every test? Why not just define it once?
t
I’m using JUnit 4. In my test cases, the HTTP responses are constant, so I wanted to avoid copying and pasting the same stubs for each test. The one that I’ve pasted here is one of many others
b
Can you try adding them to the WireMock server in the
@BeforeAll
method just to see if that works?