最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

delphi - Spring mocking syntax - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

With 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.

发布评论

评论列表(0)

  1. 暂无评论