Making a Mockery

Thanks to some example code by Ian I’ve completed my first Mockery. NMock allows you to instantiate mock objects based on interface declarations alone.
It’s already saved me a potential chicken and egg scenario where to get an instance of the normal object that’s inputting into the method I was testing I’d have had to include a project which relied on the one I was in the midst of building. Compilers tend to hate the chicken and egg question and usually go on strike.
So, NMock to the rescue and I must say it took no time at all to get up to speed with. Yes, it did require me to set all of the properties on the object that were being used, rather than relying on defaults created by Constructor methods. However, accurately controlling the data retrieved from the object is such a benefit. It will no doubt save the time spent where tests at the moment retrieve data from a database.

2 thoughts on “Making a Mockery”

  1. It was very useful. Just needed to find the time to have a play with it. And having your example code helped a great deal. So thanks again!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.