-
Notifications
You must be signed in to change notification settings - Fork 20
Load json mocks from dynamically defined directories #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
How would you like to configure it? Im thinking it can be done with an option to enable/disable loading mocks from all specified directories. And another one for all specified classpath paths. False by default. Or perhaps have an option that specifies how many parents of a specified directory, or classpath resource, should also be loaded. Default would be 0. If that would solve your issue? |
In our project we have somewhat similar use case: I want to have a base class, which sets the system up (which involves a couple of third party calls, where I want to use Wiremock). Then, a bunch of concrete tests, extending that base class. That way, whenever any of those concrete tests is executed, I first execute the logic in the base class, setting the system up and then running the test itself. Wiremock stubs to set the system up are the same for all tests, but Wiremock stubs for each individual test may be different (moreover, they may be conflicting, returning different responses for the same request in different tests). That's why I want to have a way to specify two folders here:
So that Wiremock just loads all mocks from both folders. But it currently blows up here: https://github.com/wiremock/wiremock-spring-boot/blob/main/src/main/java/org/wiremock/spring/internal/WireMockServerCreator.java#L269 |
Perhaps this can be changed in next major release. I think it might be good idea to do that when WireMock 4 is released. |
Proposal
We have a per-test directory for mocks. In resources, we have a such hierarchy:
mocks/{TestClassName}/{TestMethodName}/my-mock.json
Each mock file URL starts with a service name prefix which is taken from
ConfigureWireMock#name
property. This way mocks are loaded in to the correctWireMockServer
instance.If tests need something common, then you can put your mocks in a directory higher in hierarchy. If you put your mocks in
mocks/{TestClassName}
then those mocks will be loaded for all tests insideTestClassName
. You can put mocks inmocks
if you need something to be available in all tests.The way I match mocks to the correct
WireMockServer
might be unfeasible for some users. I guess they could put their mocks in another subdirectory, e.gmocks/{TestClassName}/{TestMethodName}/{ServerName}/my-mock.json
or name their mock files as{ServerName}.json
.Would be nice to have something like this built-in in this extension. Currently I'm just hacking in
Store
, getWireMockServer
and inject or clean-up stuff if I need. All of this is done in a customBeforeTestExecutionCallback
p.s.
ClasspathFileSource
might be a bottleneck for this use-case. In our implementation, I'm thinking about preloading all stubs in a in-memory store and load from it when needed.References
No response
The text was updated successfully, but these errors were encountered: