Monday, December 15, 2014

Rhino Mocks AAA syntax recommondations


The multiple models that are supported by Rhino Mocks (Standard, Record/Replay, Fluent, Act/Arrange/Assert) together with some weaknesses in the documentation make the software a bit unintuitive to use for the beginner - that was my own experience as well as the experience of several people I spoke to.
I personally prefer AAA syntax over the others, mainly due to the fact that this is the style which is used in many other testing frameworks both for server and client side testing.
2 things helped me a lot:

First, check out  the Rhino Mocks AAA Syntax Quick Reference assembled by Sven - thanks a lot!

Second, following Ayende's recommendations on how to use AAA make life easier:
  • In general, prefer stubs over mocks. Mocks are only necessary for complex interactions
  • Use the static MockRepository.Generate... methods instead of newing up MockRepository (see box "Create Mocks/Stubs" in the quick reference)
  • Do not use CreateMock and StriktMock
  • Use inline constraints instead of .IgnoreArguments()