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