473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Unit Testing - Mock Objects

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
2 3239
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tom Verbeure | last post by:
Hello All, so I'm now convinced that unit testing is really the way to go and I want to add it to an existing project. The first thing that I find out, is that, well, it's hard work. Harder than...
3
by: steven | last post by:
Hi, Anyone was using pmock for unit testing with python? I met a problem and hope someone to help me. For short, the pmock seems can not mock a iterator object. For example, the tested...
38
by: Christoph Zwerschke | last post by:
In August 2001, there was a thread about the "Art of Unit Testing": http://groups.google.com/group/comp.lang.python/browse_frm/thread/aa2bd17e7f995d05/71a29faf0a0485d5 Paul Moore asked the...
14
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
2
by: Naveen Mukkelli | last post by:
Hi, I'm writing a client/server application using C#. The server accepts connecitons asynchronously, using BeginAccept/EndAccept. Is there any way we can write some unit tests(NUnit) to test...
10
by: Sean Chambers | last post by:
Hello, I am attempting to utilize the MVP pattern in a new app I am building. I am using TDD, along with mock views attached to the View interface to attempt to unit test the UI. The problem I...
27
by: brad | last post by:
Does anyone else feel that unittesting is too much work? Not in general, just the official unittest module for small to medium sized projects? It seems easier to write some quick methods that are...
20
by: earthwormgaz | last post by:
Hello, I'm after doing some C++ unit testing, I'm using CppUnit. I like the look of RudeMocks, but it doesn't work for Solaris/Sparc, so its no good to me sadly. So, I have class A, and it...
4
by: Emanuele D'Arrigo | last post by:
Hi everybody, I'm just having a go with Unit Testing for the first time and my feeling about it in short is: Neat! I'm a bit worried about the time it's taking me to develop the tests but...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.