RhinoMock : Mocks Vs StrictMocks Vs DynamicMocks

Eranga Dissanayaka picture Eranga Dissanayaka · Aug 19, 2010 · Viewed 11.3k times · Source

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.

Answer

womp picture womp · Aug 19, 2010

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.