Hi there. I have a question on wire-mock. so using...
# help
g
Hi there. I have a question on wire-mock. so using wire-mock to test Feign-client APIs. the mock feign client api are called in different test classes. the unit test pass if they are running separately, but when running all the unit tests wiremock throws exception
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mockDataDirectorManagementClient' defined in com.unisoftwareplus.devicemanagementgateway.mockserver.WireMockConfig: Invocation of init method failed; nested exception is com.github.tomakehurst.wiremock.common.FatalStartupException: java.lang.RuntimeException: java.io.IOException: Failed to bind to /0.0.0.0:9561
how is it possible to set up dynamic port. using the below dependency
Copy code
testImplementation 'org.wiremock:wiremock-standalone:3.0.4'
l
This is off the top of my head at the moment but I think if you set the port to
0
it should try a dynamic port. I think there might even be a method you can use on the Wiremock options -
options().dynamicPort()
g
the question is that the feing client path should be set in application.properties file. then it cant get the correct path with random port
Copy code
feign.clent.url=<http://localhost:9561>
in application properties file
l
Ah, I see. Will need to take a look at that as I am not sure how that would work. Quick question, are you using wiremock standalone ? It looks like you have imported the standalone version with the dependency you specified above. I was wondering if it should be this import ?
Copy code
testImplementation "org.wiremock:wiremock:3.1.0"
g
yeah, using
testImplementation 'org.wiremock:wiremock-standalone:3.0.4'
Copy code
testImplementation "org.wiremock:wiremock:3.1.0"
this dependency throws exception related to jakarta if remember right
event if restarting the wiremockserver.start() and .stop() in before and after it does not help
I have implemented this approach.
o
The port is randomly assigned by default, though you might be hitting such issues when running multiple tests in parallel processes on the systems that do not have much entropy