473,802 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TDD and Mock Classes

Has anyone seen a tool for C++ that automatically creates mock
classes?

I found MockMaker for Java, but I wondered if there was something
similar for us C++ developers.

The idea is to read in the interface, and then spit out a version of
that that is suited to testing.

Sep 19 '07 #1
1 2253
earthwormgaz wrote:
Has anyone seen a tool for C++ that automatically creates mock
classes?

I found MockMaker for Java, but I wondered if there was something
similar for us C++ developers.

The idea is to read in the interface, and then spit out a version of
that that is suited to testing.
This is something of a TDD FAQ for C++, as people come from dynamic
languages and their easy mocks.

The answer is No.

Easy mocks can lead to mock abuse. In all languages, you should prefer to
mock one method at a time, not an entire object. And your code should be
decoupled enough that you don't need mocks for any internal things.

In Ruby we use Mocha to override one method - x.expects(:foo) .returns(42).
You get that in C++ by overriding a 'virtual int foo()' method. Your test
should construct an object from this derived mock class, and pass it into
the same interface as would use the real object.

--
Phlip
http://www.oreilly.com/catalog/9780596510657/
^ assert_xpath
Sep 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1976
by: John J. Lee | last post by:
I had the bright idea a week or two ago to construct mock objects (for unit testing) "by example" by calling methods on a generic mock object. Say we have a class Bar, and we want to check that, when we use BarUser in a particular way, BarUser first calls method Bar.xyzzy with args "foo" and bar=2, then method Bar.do_nothing. # first, construct a mock object by example: m = Mock()
4
1856
by: John J. Lee | last post by:
I'm trying define a class to act as a Mock "handler" object for testing urllib2.OpenerDirector. OpenerDirector (actually, my copy of it) does dir(handler.__class__) to find out what methods a handler supports. So, my mock class has to have appropriate methods defined on it. To avoid the hassle of manually defining lots of mock classes, I wanted to have a base class MockHandler so that I could do class...
1
1788
by: ischenko | last post by:
There is a (relatively) widely used technique in unit testing, called mock objects. There is even a pMock library which provides a Mock class for a Python environment. Given the "duck typing" nature of the Python itself, it's pretty trivial to build mocks without using any pre-built libraries. What is less trivial and potentially more worthwhile is to have a library of "stock" mock objects. For instance, I found myself re-implementing...
4
2393
by: David Thielen | last post by:
Hi; Are there mock objects anywhere that I can use to write nunit tests for my code behind methods? -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com
3
2445
by: Joe Van Dyk | last post by:
Say I've written a class that wraps around a particular (complex) communication service library. I want to unit test objects that use that communication service. Is the "best practice" to create a Communication_Service abstract base class that my Concrete_Communication_Service and my Mock_Communication_Service both inherit from? (and then use the mock service when unit testing)
2
3252
by: Terry | last post by:
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...
0
2232
by: Nietz | last post by:
Hi everybody, i am an user of MockPP and i like it so much, but i find that writing mock classes quite time consuming. So i decided to write one myself. By hacking the ABI (hacking on V- Table), i made a library called AMOP (http://code.google.com/p/amop/) which do not need user writing mock classes. (and any XML or Parse the source code). You can go to the wiki and take a look of the usage. And please give me some advices :)
0
1076
by: Fuzzyman | last post by:
Mock 0.4.0 has just been released, the first release in about ten months (but worth the wait). Mock is a simple library for testing: specifically for mocking, stubbing and patching. * Mock Homepage & Documentation http://www.voidspace.org.uk/python/mock.html * mock.py (module only) <http://www.voidspace.org.uk/downloads/mock.py * mock-0.4.0.zip (module, tests and documentation) <http:// www.voidspace.org.uk/downloads/mock-0.4.0.zip
4
4966
intelrate
by: intelrate | last post by:
Here is a question. I wanted my JUnit tests to be more modular and found how to mock protected methods for that purpose. Briefly speaking, we cannot mock and control calls of protected method with JDK dynamic proxy because protected methods are not in any interface but we can create MockInterface with mock method under control and call it from overridden protected method to achieve our goal. The problem I’m trying to resolve now is that my...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10536
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10304
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7598
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.