Skip to content

Instantly share code, notes, and snippets.

@vendettamit
Created June 7, 2013 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vendettamit/5728936 to your computer and use it in GitHub Desktop.
Save vendettamit/5728936 to your computer and use it in GitHub Desktop.
Rhino mock hints
1. Stub() defines the behavior for stubbed object.
2. Expect() defines the behavior and the expectation for mocked object.
3. Follow the principle of "Test only one thing per test".
4. mockrepositoryObject doesn't stop recording until you call ReplayAll. Try using repositoryInstance.PlayBack();
sample:
using (repository.Playback())
{
}
5. Call repository.VerfiyAll() in the end.
6. Use strickMock for defined behavior and expectation for method and properties call.
7. use DynamicMock for runtime auto handle support.
More on #6 and #7:
A mock is an object that we can set expectations on, and which will verify that the expected actions have indeed occurred. A stub is an object that you use in order to pass to the code under test. You can setup expectations on it, so it would act in certain ways, but those expectations will never be verified. A stub's properties will automatically behave like normal properties, and you can't set expectations on them.
If you want to verify the behavior of the code under test, you will use a mock with the appropriate expectation, and verify that. If you want just to pass a value that may need to act in a certain way, but isn't the focus of this test, you will use a stub.
IMPORTANT: A stub will never cause a test to fail.
Ref: http://ayende.com/wiki/Rhino+Mocks+3.5.ashx
8. use following statement for debugging and detailed logging
RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment