Scott Hanselman

Hanselminutes Podcast 32 - Mock Objects

September 14, 2006 Comment on this post [8] Posted in Podcast | Tools
Sponsored By

My thirty-second Podcast is up. This episode is about Mock Objects - what they are, and should you care?

We're listed in the iTunes Podcast Directory, so I encourage you to subscribe with a single click (two in Firefox) with the button below. For those of you on slower connections there are lo-fi and torrent-based versions as well.

Subscribe: Feed-icon-16x16 Subscribe to my Podcast in iTunes

Links from the show are also always on the show site. Do also remember the archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Links from the Show

RhinoMocks (i0t)
TypeMock (i5b)
Ayende Rahien (i5d)
EasyMock.NET (i57)
Example of using TypeMock (i5c)
IBM - Unit Testing with Mocks (i0p)
NMock2 (i58)
NUnit2 Mocks (i5e)
NMock vs. NMock2 Comparison (i59)
Roy Osherove on NMock2 (i5a)
We have a new sponsor this show, Aspose, the .NET and Java Component Publisher. They produce a wide variety of components with versions in both .NET and Java. Do check out their Aspose Demo Downloads as they have a huge catalog of tools to explore.

Our sponsors are Apose, CodeSmith Tools and the .NET Dev Journal. There's a $100 off CodeSmith coupon for Hanselminutes listeners - it's coupon code HM100. Spread the word, now's the time to buy.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

  • The basic MP3 feed is here, and the iPod friendly one is here. There's a number of other ways you can get it (streaming, straight download, etc) that are all up on the site just below the fold. I use iTunes, myself, to listen to most podcasts, but I also use FeedDemon and it's built in support.
  • Note that for now, because of bandwidth constraints, the feeds always have just the current show. If you want to get an old show (and because many Podcasting Clients aren't smart enough to not download the file more than once) you can always find them at http://www.hanselminutes.com.
  • I have, and will, also include the enclosures to this feed you're reading, so if you're already subscribed to ComputerZen and you're not interested in cluttering your life with another feed, you have the choice to get the 'cast as well.
  • If there's a topic you'd like to hear, perhaps one that is better spoken than presented on a blog, or a great tool you can't live without, contact me and I'll get it in the queue!

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
September 14, 2006 10:41
Thirty SECOND show? Wow! I can't imagine how you're going to cover a subject like Mock Objects in 30 seconds. I'm impressed! ;-)
September 14, 2006 10:50
Ian - :P

"Mock Objects are neat. Use them. Use them again and again."

Boom, that was like 14 seconds.
September 14, 2006 14:09
Scott,

I've been using Rhino for several months now, and feel quite comfortable with the toolset.

You mention during this podcast that it's sometimes difficult to get around the "virtual method" requirement in order to mock an object. The solution that I've implemented is to add conditional compilation statements around the declaration of methods that I intend to mock that I want to be sealed or final in the production release of my code.

September 14, 2006 15:27
I've been using Rhino Mocks lately as well and I'm fairly happy with it. The virtual method requirement hasn't caused me too much grief, because mostly I need it when I'm mocking interface implementations (of which I'm using a lot lately, coupled with Windsor Container as the IoC implementation). Seems to work just fine for me, and the way expectations are expressed in Rhino suits me.
September 14, 2006 18:15
I like to mock objects. It makes me feel superior.
September 14, 2006 19:20
Scott:

(Sorry for the email spam, I now see this comment section, so posting here)

Enjoyed the show. As always, picked up some previously unknown technologies – I knew about NUnit and NMock (and DotNetMock, which you didn’t mention), but not about Rhino nor TypeMock. Can’t wait to try TypeMock, could be really helpful for me.

A couple of points I thought could have been added for clarity
1. Mock objects are not for mocking your test subject, but its dependencies.
2. A useful way of comparing normal unit testing with the use of mock objects is that normally you run tests, then dissect your objects and make sure things went right (the atom smasher approach). Mock objects allow you to test the actual interactions of objects. This is another benefit of mocks that I didn’t think really made come through in the discussion.

ServiceStub [Fowler, P of EAA] is a pattern that can be used as an alternative to mock objects – probably not suitable for the podcast, but I do hear it used instead of mock objects. But it places more requirements on your code.
September 14, 2006 20:08
Dave,

I see ServiceStub as being a pattern more useful in functional/performance testing than on unit tests, but it does have a purpose and the basic idea is certainly the same (or at least pretty close) to the mocking idea, anyway.
September 15, 2006 4:02
Tomas:

Personally, I agree with you, but it's a philosophical thing. Some people are definitely out there using ServiceStub for unit testing (including Fowler, who said in an interview I read something to the effect of "we use service stubs instead of mock objects. Nothing wrong with mock objects, but we do our testing differently.")

I think the point is that ServiceStub is used to replace an expensive and hard-to-work-with service (e.g. external, database, etc.) to enable testing of dependent classes. Mock objects give you that, but a whole lot more to boot (like interaction validation)

It's worth reading Fowler's article "Mocks Aren't Stubs"

Interesting to note that he suggests using mock objects to implement stubs.

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.