When I use DSharp.Testing.Mock I can use the following syntax:
FMyMock.Setup.WillReturn(1).Exactly(2).WhenCalling....
FMyMock.Setup.WillExecute.Exactly(2).WhenCalling....
but what is the equivalent syntax if I use Spring.Mocking?
When I use DSharp.Testing.Mock I can use the following syntax:
FMyMock.Setup.WillReturn(1).Exactly(2).WhenCalling....
FMyMock.Setup.WillExecute.Exactly(2).WhenCalling....
but what is the equivalent syntax if I use Spring.Mocking?
Share Improve this question edited Feb 17 at 15:28 mjn 36.7k30 gold badges182 silver badges385 bronze badges asked Feb 16 at 22:03 pio piopio pio 7961 gold badge9 silver badges30 bronze badges1 Answer
Reset to default 1With Spring.Mocking
you don't need to explicitly define any expectation if it should not return a specific value when using Dynamic
mode (which is the default mode). Only the Strict
mode needs specifying every expectation.
However you don't specify the number of expected calls - if you wish to verify the number of calls, then you use mock.Received(...)
after you execute the code you wanted to test.
If you want to return different values for subsequent calls, then you can specify multiple values on the Returns
method. Or you explicitly specify a param matcher for the different return values if the input parameters have different values.
But the overall philosophy is to write less mocking code to achieve the testability of your SUT. The more mocking code you write, the more you risk assuming internals of your implementation that might change in the future and break your tests.