wiremock-extension icon indicating copy to clipboard operation
wiremock-extension copied to clipboard

Reusing server(s) between each test

Open celcius112 opened this issue 7 years ago • 1 comments

Hi,

First of all, I would like to thank you for this extension. I really like this simple but expressive API :).

I have a suggestion for the extension lifecycle callback: I think creating and stopping server(s) for every test is unnecessarily costly. Was there a reason why you did it that way ?

One way would be to do like the WireMockClassRule rule:

  • Before each method, we check whether the server is running using the method WireMockServer#isRunning(). - If it is running, reset the mappings on the server's client - If it is not running, start and configure it

Another solution would be to use JUnit 5's store, so that we can easily share server instances between tests (while not forgetting to reset the server(s) before or after each test).

With your current implementation it might require some refactoring. That's why I wanted to have your opinion before submitting a PR.

Thank you !

celcius112 avatar Jun 18 '18 15:06 celcius112

Hi,

you are right, currently there is no pendant to the WireMockClassRule yet. I also like the idea of the ExtensionContext.Store you mentioned. Maybe this is the JUnit 5 way to go and worth the effort. If you have something in mind feel welcome to provide another PR.

Best wishes.

JensPiegsa avatar Jun 20 '18 22:06 JensPiegsa