Can you explain the difference between StrictMock and Partialmock?

How do I use RhinoMocks version 3.6, and since I do not use Record-Replay, and since I do not call Verify methods for approval on mocks;

Can you explain what the difference between is very simple?

MockRepository.GenerateMock() MockRepository.GeneratePartialMock() MockRepository.GenerateStrictMock() 

Note. I use .GenerateMock all the time to create my mocks and I call method calls, providing already pending arguments.

+7
source share
2 answers

The differences are explained in this article.

If you do not create any expectations in StrictMock and the method is called in mock, an exception will be thrown.

If you do not create any expectations in PartialMock , and the method is called in the layout, nothing special happens. If this layout comes from a base class, the call expires before the existing base implementation.

There is also something called DynamicMock . If you do not create expectations in DynamicMock , and the method is called in the layout, the stub method is called. If there was a return value, the default value is returned (for example, null or 0 ).

GenerateMock I believe that creates DynamicMock .

Ayende chose this default because he recommends the ideal using only DynamicMock and Stub . StrictMock creates fragile tests and usually violates the concept of only testing one behavior per test.

See this article: http://ayende.com/wiki/Rhino%20Mocks%203.5.ashx#CreateMockisdeprecated,replacedbyStrictMockTheuseofStrictMockisdiscouraged

I also saw how he said that it is useful to start with severe bullying, and work with your tests back to dynamic layouts / stubs, when you are comfortable with how your test code behaves. There is no link for this:

+16
source

I should add that “using Strict Mock is discouraged” by Ayende. http://ayende.com/wiki/Rhino+Mocks+3.5.ashx#CreateMockisdeprecated,replacedbyStrictMockTheuseofStrictMockisdiscouraged

He says:

Severe bullying will fail if something is not expected of them. Ultimately, this means that any change to the code in the test may violate your tests, even if the change has nothing to do with what you are actually testing in this particular test.

I recommend using cigarette butts and dynamic layouts.

0
source

All Articles