By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,896 Members | 1,983 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,896 IT Pros & Developers. It's quick & easy.

Unit Testing - Mock Objects

P: n/a
I'm looking at NMock2 as a framework to create mock objects during my unit
testing. One part that I'm trying to understand is that it will mock
interfaces, not concrete classes. I normally don't create interfaces for
every class. For example I normally don't have an interface for my business
object classes. A business object class is going to have too many unique
methods that I don't see the point of creating an interface that will only
ever have one class that implements it. That seems like overkill. However
if I want to mock the business object, it seems that with NMock2 I will need
to create an interface.

Am I understanding this correctly? Is my approach to interfaces wrong?

It looks like RhinoMock can mock interfaces or virtual methods of classes.
This raises a similar questions because I normally don't make everything
virtual. It seems like these frameworks would force me to change how I
design my classes to fit the frameworks. Is this right?

Any insights would be appreciated.

Thanks
Terry
Sep 28 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Terry,

Since NMock2 is a product from 3rd party software vendor, we may not be
able to provide you with useful information on this issue. In this case,
let's wait to see if any community member can shed some light on it.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Sep 29 '06 #2

P: n/a
Terry <te***@newsgroup.nospamwrote:
I'm looking at NMock2 as a framework to create mock objects during my unit
testing. One part that I'm trying to understand is that it will mock
interfaces, not concrete classes. I normally don't create interfaces for
every class. For example I normally don't have an interface for my business
object classes. A business object class is going to have too many unique
methods that I don't see the point of creating an interface that will only
ever have one class that implements it. That seems like overkill. However
if I want to mock the business object, it seems that with NMock2 I will need
to create an interface.

Am I understanding this correctly? Is my approach to interfaces wrong?

It looks like RhinoMock can mock interfaces or virtual methods of classes.
This raises a similar questions because I normally don't make everything
virtual. It seems like these frameworks would force me to change how I
design my classes to fit the frameworks. Is this right?
Yes, that's pretty much right in my experience. However, I've found
that creating an interface makes it more obvious which parts of the
class are really required. Programming to that interface before you
have an implementation helps you to do design the class as you go,
which I find helpful. It also means you can test classes using that
interface before implementing it.

I certainly wouldn't like to try unit testing without having mocks
available :) I personally use EasyMock 2 in Java and a customised
version of EasyMock.NET for .NET. EasyMock.NET isn't likely to go
anywhere though - I'd suggest using RhinoMocks, from what I've seen of
it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.