Strict mocking vs Loose mocking

By | May 6, 2015

Strict mocking vs Loose mocking is a question something which comes up often when various mocking frameworks like Moq, NSubstitute, Rhino Mocks, FakeItEasy are compared.

So what is it?

Suppose you create a fake of a class and do not configure the behavior of one of its method or property.

Strict mocking:  If the test method invokes that method or property, then BAM !!! Say hello to Mr Exception.

Loose mocking: If the test method invokes that method or property, then you get the default value for that operation (which mostly will be a zero or a null).

FakeItEasy by default supports loose mocking. That said, it is not that FakeItEasy cannot support strict mocking. It does. More information here.

Leave a Reply