[英]MOQ Unit Test - Assert Vs Verify
Am trying to understand what Exactly Verify or VerifyAll Does ? 我是否在试图确切地了解Verify或VerifyAll的作用?
I was searching and i got the below info on using MOQ 我正在搜索,并且得到了以下有关使用最小起订量的信息
Arrange
Mock
Set up expectations for dependencies
Set up expected results
Create class under test
Act
Invoke method under test
Assert
Assert actual results match expected results
Verify that expectations were met
So What exactly does Verify Does? 那么验证到底能做什么? I can test everything using Assert and in case if any failures the unit test will fail ?
我可以使用Assert测试所有内容,以防万一单元测试失败了?
What extra work does verify does ? 验证还有哪些额外的工作? Is it the replacement for Assert ?
是Assert的替代品吗?
Some more clarify will make me understand. 一些进一步的澄清会使我理解。
Thanks 谢谢
Assert is used to do checks on the class/object/subject under test (SUT). 声明用于对类/对象/被测对象(SUT)进行检查。 Verify is used to check if the collaborators of the SUT were notified or contacted.
验证用于检查是否已通知或联系了SUT的协作者。
So if you are testing a car object, which has an engine as a collaborator/dependency. 因此,如果您要测试具有引擎作为协作者/依赖项的汽车对象。 You would use to Assert to see if car.IsHumming after you invoke car.PushStart() You would use Verify to see if _mockEngine.Ignition() received a call.
在调用car.PushStart()之后,您将使用Assert来查看car.IsHumming是否可用。使用Verify来查看_mockEngine.Ignition()是否收到了调用。
Approach One: 方法一:
Approach Two 方法二
So if you have multiple operations on the Mock OR if you need the mocked method to return a value which will be processed, then Setup + Act + VerifyAll is the way to go 因此,如果您在Mock上执行了多项操作,或者需要模拟方法返回将要处理的值,则可以使用Setup + Act + verifyAll
If you have a few notifications that you want to be checked, then Verify is easier. 如果您有一些要检查的通知,则“验证”会更容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.