Wednesday, April 25, 2007

Unit Testing With Mock Objects - Slides and Sample Code

Thanks to everyone who attended my mock objects talk at Innotech today, I hope it wasn't too obvious that it was the first time I've presented at a conference ;-) As promised, I've posted my slides and source code here. Sorry about the ads, but Blogger doesn't support file uploads and this site was the best I could find on short notice. If you're here for the links, here you go:

If you have any additional resources you'd like to share, let me know and I'll post them here.

Thanks again,
John

4 comments:

Jason said...

Hey Man,
I wish I could have been there. I hope everything went well. I'll check out your info. Sounds like really cool stuff.

Jason

Steve Freeman said...

It looks like a good presentation from the slides -- nice images. One thing you might want to think more about, though, is the effect that TDD with mocks has on your design. That's our main interest, rather than avoiding external infrastructure.

John Hann said...

First off, thanks! If you happen to live in the Portland area, I'll be giving the same talk at Code Camp this year. With regard to the design benefits of TDD with mocks, I think that the prospect of refactoring an architecture to enable mocks is a negative for some people. I fall into the YAGNI camp when it comes to design, and I think there is a cost to making uber-pluggable code with interfaces for everything or dependency injection frameworks. If you weren't building this into your application to begin with, you probably don't need it.

When recommending the usage of mock objects to test a particular class, I've had the most success by explaining that the test will no longer have to go to the database, web service, credit card gateway, etc. that the class is depends on. This is usually the pain point that drives a developer to consider mock-based testing at all. If the external dependencies aren't cumbersome, it's usually easier to simply use the external entity. The code may not be as flexible, but that may not matter for that particular application.

What specific design benefits do you see coming from a TDD with mocks approach to development?

Paulo Caroli said...

Hey John,
I am glad to find your page.
It has a lot of good information on Mock Objects.
I created a page with some good examples on Mock Objects. Check it out at: http://www.mocksamples.org/
Cheers,