6

I have,

class CFoo : public CFooPar
{
   public:
      CFoo(){}
      ~CFoo(){}

      virtual bool ret() const
      {
         return true;
      }
};

How can I create mock class for this virtual bool ret() const method?

Thank you!

mat007
  • 905
  • 8
  • 16
domlao
  • 15,663
  • 34
  • 95
  • 134

2 Answers2

10

I use Google Mock for that (https://code.google.com/p/googlemock/wiki/V1_6_ForDummies).

With that tool, the mock reads

#include "gmock/gmock.h"
class MockCFoo : public CFoo {
    public:
    MOCK_CONST_METHOD0(ret, bool());
};
rcomblen
  • 4,579
  • 1
  • 27
  • 32
1

If you mean using turtle here it is :

#include <turtle/mock.hpp>

MOCK_BASE_CLASS( MockCFoo, CFoo )
{
    MOCK_METHOD( ret, 0 )
};

The rest depends on how you use CFoo in your production code, however it would likely be similar to the turtle motivation case I suppose.

mat007
  • 905
  • 8
  • 16