NAVmoble - the pocket-sized ERP
Optimized for Microsoft Dynamics NAV and Windows Mobile powered devices

Friday, July 02, 2004

Mock objects ?

Mock objects is an approach for testing interactions between components by faking the behaviour of the components from external libraries.
They are must have knowledge if one is trying to utilize TDD methodology.
Some of the wide spread statements about the reasons to use mock objects are:

  • They are easily created and set up.

  • Usually they work very fast comparing to the original implementations

  • They are deterministic.


  • Testing with mock objects improves domain code by preserving encapsulation, reducing global dependencies and clarifying the interactions between classes. I am impressed by this concept, however using mock objects raises some additional problems. As with any unit testing, there is always a risk that a mock object might contain errors / actually this threat is valid for unit testing as a whole /. In some cases it is difficult to create mock objects that represent types in a complex library.
    However having mock objects in our toolset is vital for writing elegant and useful unit tests


    There are some .NET mock object libraries and the one I like the most is NMock

    No comments: