views:

575

answers:

3

Hi,

Is it possible to create a "strict" mock using the new AAA syntax of Rhino Mocks? The issue I am seeing is that the library I am mocking often returns null as a valid return value (which I handle in my function), so using the default mock I can never be sure if I tested all paths or I forgot to set some expectations.

+2  A: 

MockRepository.GenerateMock<T>() should return a 'strict' mock - as opposed to MockRepository.GenerateStub<T>(), but couldn't you just define an explicit method setup that returns null?

Mark Seemann
I can see only MockRepository.GenerateMock<T>(), but it doesn't work - unexpected calls still just return null.
Grzenio
It just adds to the pain, because I have to debug the test every time I forget to setup the method to figure out which one was it.
Grzenio
Sorry, I misremembered the name. Edited now.
Mark Seemann
+3  A: 

I Rhino Mocks 3.6 we finally have: MockRepository.GenerateStrictMock<T>(). GenerateMock does not create strict mocks.

Grzenio
A: 

They functionality has changed and GenerateMock() doesn't return a strict mock. StrictMock is still available for use. Just not under the new syntax.

Ayende talks more about how CreateMock is deprecated, replaced by StrictMock here.

Note:
Added new answer so people can easily find Ayende thoughts on the change.

Ralph Willgoss