Hi Team, I have written this code for wiremock int...
# wiremock-java
s
Hi Team, I have written this code for wiremock integration testing with spring boot. Trying from few days, but getting this error. "Request was not matched because no stubs registered". 404 error. Can someone please suggest where the actual issue might be there. I have tried with the simplest stub also as possible, but still getting the same result.
t
Hi @Shruti Mishra, it’s hard to tell for certain without seeing all the code, but I think one of two things could be happening: 1. You have another (empty) WM instance running and that’s the one your code under test is connecting to, rather than the one you’re start via the JUnit extension. 2. You’re calling some of the code you’re testing before the stubbing call e.g. during initialisation.
s
Hi @Tom I have added the code snippet above for the code reference, maybe you have referred that. In that wiremockextension instance which I have created above, the same I am referring to, the the stubFor method.
t
I can’t tell from this how you’re getting the WireMock base URL into your code under test or when/how you’re calling that code, so without being able to see that I can’t suggest anything more specific.
s
Actually baseUrl is the commented out code @Tom.
t
That might be the problem then. If you’re not setting the app code’s base URL to one with the dynamically chosen port, it’ll probably default to another, fixed port e.g. 8080 and I’m guessing you have another instance running on that one that has no stubs.
BTW, I also noticed this, which won’t work:
WireMock.get("/parties")
Instead you need
WireMock.get(urlPathEqualTo("/parties"))
so that you can work with query parameters separately.
s
Can you please provide an example of setting base url, earlier I had set it by using properties file, but I guess I did in the wrong manner. Regarding the port, wiremock is running on port 8082, on which no other instance is running which I have verified.
Regarding Wiremock.get(urlPathEqualTo) I have tried earlier with this approach, but due to some reasons it did not worked
t
The
.dynamicPort()
in your extension setup will put WireMock on a random port. So it seems whatever is running on 8082 isn’t the one you’re stubbing against.
Sounds like there must be something starting up another instance on a fixed port of 8082
s
Actually I saw on the eclipse console, in order to verify on which port it is running...from there came to know 8082...even from cmd I have checked but nothing was running apart from this in 8082 @Tom