4

In my Quarkus application I have multiple controllers which use multiple rest clients. I have multiple tests which all use a @QuarkusTestResource with a Wiremock resource. My approach was for each controller to have it's own Wiremock resource and stub whatever restclients they need and how the stubs needs to be defined. So each test might stub out the same rest client but with different stubs.

When running my test I found that even if each test class is annotated with a different Wiremock implementation they overwrite each other it seems like. The tests are probably run in parallel and the configuration (/mp-rest/url) is shared between them and overwritten by the QuarkusTestResourceLifecycleManager that ran last.

Any tips on how to solve this? Or should I just create one Wiremock class for each rest client?

KOT
  • 1,986
  • 3
  • 21
  • 35
  • Is each WireMock client assigned to a separate port? If they are assigned to the same port, it would probably fail to actually generate a separate client, and only have one. – agoff Mar 10 '21 at 14:24
  • Yes, different ports – KOT Mar 23 '21 at 20:54

1 Answers1

2

I think you can use restrictToAnnotatedClass in QuarkusTestResource for that. It is available in at least Quarkus 1.13. See: https://quarkus.io/guides/getting-started-testing

You can also use

wireMockServer = new WireMockServer(new WireMockConfiguration().dynamicPort());

to define a dynamic port to each WireMock server

alexander
  • 1,191
  • 2
  • 20
  • 40