Search This Blog

11 August 2010

Mocking of objects

When testing an application that interacts with other external systems or that access a database you need some handling for this to make this work correctly.

Either you need some test versions of the systems and setup the database similar as the production database which is cubersome and lot of work to make each test work. A slight change in the object model would require that the tests also are changed.

A better method is to use some mocking framework to simulate that certain calls are being made and check that this really happens in the test. There exists several such mocking frameworks that have different advantages and disadvantages.

In the projects I'm currently working with we use a mocking framework developed by Mikael Waltersson which is called Simple Mock. This mock framework is as the name specifies very simple to use but don't be fooled the easy of use doesn't imply that the mock framework lacks functionallity, instead it has the functionallity that is required for a mock framework.

Try it, the time you spend learning how to setup the framework for your project will be earn quick enough once you start writing more and more tests.

Link to the development page on codeproject: http://www.codeproject.com/tips/45376/Simple-Mocking-new-mocking-framework-for-NET-3-5.aspx

 

No comments:

Post a Comment