-
Notifications
You must be signed in to change notification settings - Fork 74
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
Named mocks #92
Comments
Can you provide some code examples of what this would look like? |
Sure. This is pseldocode, although I have done my best to make it feel like rust. It does not represent a extremely real use case, but it gets close. The main point here is that we might want to verify expectations on mocks when the "original" mock object is already gone and before the mock server goes out of scope. Main reason for that is that parts of these processes might happen in different functions (like ucumber style enforces) or that you might want to make a more elaborate verification. I have of course not provided an implementation, because I will do it only if you agree first with the proposal. Rust is a great language for systems development, but it is also great for webservices development or anything else (almost). We just need to provide the developpers with a more convinient eco system and this crate for me leads RUST towards this goal. However, use cases like this one are not uncommon on webservices development or in other cases where integration tests are important, sometimes with greater prevalence than unit tests. If you could accept something like this it would be tremendously helpful for many developers, myself surely considered here.
|
A slightly simpler version of this, which would be fantastically useful, would be to just be able to get the number of calls to a mock that was itself given a name. Something like:
Then the calls can be asserted later by doing:
Or possibly even something similar to
Simpler still would be if the
|
Thanks for pitching in @sazzer! |
Hello @LukeMathWalker, Could you clarify what received_requests_for_named_mock means exactly? There are two proposals, mine and @sazzer 's. ARe you whiling to accept both? @sazzer my main question here is that, for my scenarios to work, I need to be able to assert after mocks theirselves are out of scope, so that I can assert in latter steps of the flow. I am not sure if your proposal covers that. If it does, then I think we might stick with yours. |
So, my desire was to use Wiremock as a fake remote API for integration tests. So it would be set up without expectations to always act as the remote service, and then have the ability afterwards to assert that calls either were made or were not made. For my personal ask, whether the mocks have gone out of scope or not doesn't really matter. It was literally just "Given the name of a mock, how many times was it triggered" - which would work perfectly well whether they were out of scope or not. |
I agree, this is also my issue, because the way it is, if mocks are out of scope before calls are made you have no way of asserting . If you do add expectations and mock is out of scope before calls are made, a panic will take place. I can try and code, something, unless you intend to do so. Just let me know.Obrigado,MarlonEm 28 de jan. de 2023, à(s) 10:55, Graham Cox ***@***.***> escreveu:
So, my desire was to use Wiremock as a fake remote API for integration tests. So it would be set up without expectations to always act as the remote service, and then have the ability afterwards to assert that calls either were made or were not made.
For my personal ask, whether the mocks have gone out of scope or not doesn't really matter. It was literally just "Given the name of a mock, how many times was it triggered" - which would work perfectly well whether they were out of scope or not.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Go for it :) I've not had time to look at it yet! |
This is what I'd lean towards, but we can't modify the For the sake of backwards compatibility, I'd suggest adding a new What do you think? |
Hello,
Can you evaluate the following proposal?
If you agree, I can provide a PR.
Proposal
This issue aims to propose a named mock.
use case
Currently, mock expectations are verified once the wiremock server goes out of scope.
However, there are situations where we need to verify if side effects have happened before a wiremock server has the chance to go out of scope.
One (but not the only one) example is when a domain driven design test model is being used. For example, cucumber style tests need to verify if something has happened before the test ends, in a then function.
There are also situations where one wiremock server is used to support several tests running sequentially.
To support these use cases, we propose the creation of named mocks.
Named mock
A named mock shares several characteristics of the classical mock. It however:
side effects
This addition will not break usage for those who are already using this project, while enabling other use cases.
The text was updated successfully, but these errors were encountered: