TDD and Mock Classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • earthwormgaz

    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.

  • Phlip

    #2
    Re: TDD and Mock Classes

    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

    ^ assert_xpath

    Comment

    Working...