什么是Moq VerifyNoOtherCalls()方法的FakeItEasy等效项 [英] What is the FakeItEasy equivalent of the Moq VerifyNoOtherCalls() method

查看:110
本文介绍了什么是Moq VerifyNoOtherCalls()方法的FakeItEasy等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前是Moq用户,正在研究其他模拟框架.

I'm currently a Moq user and I'm researching other mocking frameworks.

在进行单元测试时,我经常调用_mock.VerifyNoOtherCalls(),因此可以确定除了已经验证的交互之外,没有意外的交互.

When unit testing I frequently call _mock.VerifyNoOtherCalls() so I can be certain there are no unexpected interactions beyond the ones that I have already verified.

我已经搜索了FakeItEasy文档,但在其框架中找不到等效的选项.谁能建议我该怎么做?

I've searched the FakeItEasy docs and cannot find the equivalent option in their framework. Can anyone suggest how I might do this?

推荐答案

严格的假货

FakeItEasy支持严格限制伪造(类似于Moq中的严格模拟) :

FakeItEasy supports strict fakes (similar to strict mocks in Moq):

var foo = A.Fake<IFoo>(x => x.Strict());

一旦发生意外呼叫,此操作将失败.

This will fail the moment an unexpected call is made.

半严格假货

还可以配置,并将其与

and combine this with specifying different behaviors for successive calls, however in this case, there's no benefit to doing so over using a strict fake, as a strict fake will give better messages when unconfigured methods are called. So if you want to configure some methods to be called a limited number of times, you could

var fakeShop = A.Fake<IShop>(options => options.Strict());
A.CallTo(() => fakeShop.GetTopSellingCandy()).Returns(lollipop).Once();
A.CallTo(() => fakeShop.Address).Returns("123 Fake Street").Once();

fakeShop.GetTopSellingCandy()fakeShop.Address可以调用一次,第二次失败.

fakeShop.GetTopSellingCandy() and fakeShop.Address can be called once, the second time it will fail.

任意支票

如果您要检查测试中的任意点是否没有通话:

If you want to check if no calls are made at arbitrary points in the test:

A.CallTo(fakeShop).MustNotHaveHappened();

最好过滤掉一些在调试时可以执行的方法:

It might be better to filter out some of the methods that can be executed while debugging:

A.CallTo(a)
 .Where(call => call.Method.Name != "ToString")
 .MustNotHaveHappened();

您不希望测试失败,因为您将鼠标悬停在变量上.

You don't want a failing test because you hovered over the variable.

这篇关于什么是Moq VerifyNoOtherCalls()方法的FakeItEasy等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆