Faking interfaces with events or delegates using Rhino Mocks – level 300

I think mock objects themselves are a 300-level topic.  I wish it weren’t so, but from the folks I talk to, the average developer doesn’t use them.  Fakes, stubs, mocks (whatever you want to call them – and I know they overlap, and I understand the semantic differences among them) are critical for testing.  It’s important to isolate code under test, and in order to do that, we have to fake out other classes the current class talks to.  Not all the classes as a rule, but the ones that might give our test unpredictable results.

Phil Haack lays out an example faking an event on an interface.  While I prefer to use plain delegates for my view-controller notification, events are multicast delegates, so the work as well.  Give it a read.

http://haacked.com/archive/2006/06/23/UsingRhinoMocksToUnitTestEventsOnInterfaces.aspx

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

One Response to Faking interfaces with events or delegates using Rhino Mocks – level 300

  1. Hey Jeff,

    I give a demonstration of this technique in a screencast I made a couple of weeks ago. The link to the screencast is here : http://www.jpboodhoo.com/blog/ScreencastAppliedTestDrivenDevelopmentForWebApplicationsPart3.aspx.

    My recommendation is to download the flash file and play it using the GlobX Swiff player.

    Thanks

Leave a Reply