简体   繁体   中英

Rhino Mocks: “Verify” vs. “Assert”

使用Rhino Mocks时,何时使用“VerifyAll”以及何时应该“断言”?

VerifyAll and Verify are used to check that some methods have been called (and possibly verify the parameters with which they were called). This is considered "interaction-based testing", and is used when you want to verify that the system-under-test calls a method on one of its dependencies.

Asserts normally means that you want to make sure the value returned has the correct value. Asserts are used for what is called "state-based testing", which is essentially verifying the state of the system-under-test after it has been acted upon.

verifyall, check out this .

Also, differentiate Mock and Stub .

I believe VerifyAll belongs to the older style of using RhinoMocks, where you would have a record step and a playback step, after which you would verify all Expectations. In this model you would during the record step set up an expectation (eg, Expect that this method will be called with parameters x, y, and z, etc).

The newer versions of RhinoMocks introduce Arrange-Act-Assert (AAA) syntax as the preferred pattern; Using this pattern, it makes more sense to use Assertions at the end of your test method. It is still possible to use VerifyAllExpectations(), but personally I think it reads easier if all of your Assertions happen in a block at the end of the test.

So I guess the answer (to me anyway) is that it is personal preference; See the link above where he has several examples of the same test and choose the one that reads best to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM