5

I'm using Rhino Mocks in my unit test.

I would like to know the difference between STUBS and MOCKS (mocks.Stub<T>() and mocks.StrictMock<T>()).

Matthew Crumley
  • 101,441
  • 24
  • 103
  • 129
Yuriy
  • 51
  • 2

1 Answers1

6

I think it had been asked before.

It is generally the same with the following differences:

  • Strict Mocks throw exceptions on each call which had not been expected
  • Dynamic Mocks accept unexpected calls und just return default values (eg. null)
  • Stubs are like dynamic mocks but have "property behaviour" turned on by default. This allows writing and reading properties like fields, but doesn't allow Stub, Expect nor AssertWasCalled on properties. This behaviour can also be configured on a normal Mock too. But for stubs it is the default.

Since Rhino changed to AAA syntax, it is discouraged to use Strict Mocks, since they make test code very hard to maintain.


Similar questions:

I can't find the information about the Rhino implementation, so I don't mark this question as duplicate.

Community
  • 1
  • 1
Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193