Hanselminutes Podcast 32 - Mock Objects
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.
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
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.
- Some other clients are Doppler (also suppose Windows CE), FireAnt, Nimiq, and PrimeTime Podcast.
- 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.
About Newsletter
"Mock Objects are neat. Use them. Use them again and again."
Boom, that was like 14 seconds.
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.
(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.
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.
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.