473,406 Members | 2,371 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,406 software developers and data experts.

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 2235
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
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,...
4
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...
1
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"...
4
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
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...
2
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...
0
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),...
0
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...
4
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...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.