如何使用 FakeItEasy 检查是否一定发生了对任何重载的调用?
我有一个正在测试的方法。给定某些输入,它应该向记录器(ILogger)写入失败方法。该接口有几个 Log() 重载,以及一些属性(例如日志记录级别)。我正在使用 FakeItEasy 嘲笑记录器。
我想断言的是对 Log() 的调用已经发生。但是,我不关心使用了哪个特定的重载。我该怎么做?
我的想法:
// Doesn't work, since a different overload (with more parameters) is used.
A.CallTo(() => mockLogger.Log(null)).WithAnyArguments().MustHaveHappened();
// "Works", but if the code were to call something else on the logger
// (ex. change the logging level), this would also pass!
Any.CallTo(mockLogger).MustHaveHappened();
I have a method which I am testing. Given certain inputs, it should write a failure method to the logger (an ILogger). The interface has several overloads for Log(), as well as some properties (ex. a logging level). I am mocking the logger using FakeItEasy.
What I want to assert is that a call to Log() has happened. However, I don't care about which specific overload got used. How can I do this?
My ideas:
// Doesn't work, since a different overload (with more parameters) is used.
A.CallTo(() => mockLogger.Log(null)).WithAnyArguments().MustHaveHappened();
// "Works", but if the code were to call something else on the logger
// (ex. change the logging level), this would also pass!
Any.CallTo(mockLogger).MustHaveHappened();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑
这可以使用以下语法来完成:
原始答案
没有简单的方法可以做到这一点,并且 - 如果我错了,请纠正我 - 我认为没有在任何模拟框架中。
话虽如此,下面的示例中提供了一种不太简单的方法来做到这一点。
Edit
This can be done using the following syntax:
Original answer
There's no easy way of doing that, and - correct me if I'm wrong - I don't think there is in any mocking framework.
That being said there is a - not so easy - way to do it provided in the example below.