views:

568

answers:

2

When using Rhino Mocks, when is it appropriate to use "VerifyAll" and when should I do "Asserts"?

+1  A: 

VerifyAll and Verify normally means that you want to make sure some methods have been called.

Asserts normally means that you want to make sure the value returned has the correct value. Assert is a general concept to verify the value, and I don't think there is anything special in Rhion mocks about that.

verifyall, check out this.

Also, differentiate Mock and Stub .

J.W.
+2  A: 

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.

Chris Shaffer