Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RhinoMock : Mocks Vs StrictMocks Vs DynamicMocks

Tags:

I understand the difference between a Mock and a Stub.

But different types of Mocks in RhinoMock framework confuses me.

Could someone explain the concepts of Mocks Vs StrictMocks Vs DynamicMocks in terms of RhinoMock framework.

your answers are greatly appreciated.

like image 873
Eranga Dissanayaka Avatar asked Aug 19 '10 20:08

Eranga Dissanayaka


People also ask

Which is a valid mock type using Rhino?

Mock OptionsStrict Mock. A strict mock requires you to provide alternate implementations for each method/property that is used on the mock. If any methods/properties are used which you have not provided implementations for, an exception will be thrown. Dynamic Mock.

What is strict mock?

To summarize, a strict mock will fail immediately if anything differs from the expectations. On the other hand, a non-strict mock (or a stub) will gladly "ignore" the call to foo.


1 Answers

A strict mock is a mock that will throw an exception if you try to use any method that has not explicitly been set up to be used.

A dynamic (or loose) mock will not throw an exception if you try to use a method that is not set up, it will simply return null a default value from the method and keep going.

It is highly recommended to use dynamic mocks, as strict mocks generally turn out to be a maintenance nightmare. Here's a good blog post that has a code example of strict vs. dynamic, and why strict mocks are usually a bad idea.

like image 95
womp Avatar answered Jan 04 '23 02:01

womp