Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rhino Mocks: "Verify" vs. "Assert"

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

like image 818
Tato Avatar asked Mar 28 '09 02:03

Tato


2 Answers

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 .

like image 195
J.W. Avatar answered Oct 11 '22 02:10

J.W.


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.

like image 31
Chris Shaffer Avatar answered Oct 11 '22 01:10

Chris Shaffer