Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old September 19th, 2007, 04:05 PM
earthwormgaz
Guest
 
Posts: n/a
Default 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.

  #2  
Old September 19th, 2007, 06:45 PM
Phlip
Guest
 
Posts: n/a
Default Re: TDD and Mock Classes

earthwormgaz wrote:
Quote:
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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.