TDD and Mock Classes

E

earthwormgaz

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.
 
P

Phlip

earthwormgaz said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top