title: Google Mock: How to test this code?
body: <p>I wrote the following piece of code to test <code>Xyz::xyz_func</code> by mocking <code>Abc::abc_func</code> using Google Mock.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "gmock/gmock.h"
  #include "gtest/gtest.h"
  
  using namespace std;
  using ::testing::_;
  using ::testing::Return;
  
  class Abc
  {
      public:
          virtual ~Abc() {}
  
          virtual bool abc_func(int arg)  = 0;
  };
  
  class MockAbc : public Abc
  {
      public:
          virtual ~MockAbc() { }
  
          MOCK_METHOD1(abc_func,  bool(int arg));
  };
  
  class AbcImpl : public Abc
  {
      public:
          virtual bool abc_func(int arg)
          {
              cout &lt;&lt; arg &lt;&lt; " :: " &lt;&lt; __FILE__ &lt;&lt; " :: " &lt;&lt; __LINE__ &lt;&lt; endl;
              return true;
          }
  };
  
  class Xyz : public AbcImpl
  {
      public:
          virtual ~Xyz() {}
          virtual bool xyz_func()
          {
              AbcImpl obj;
              return obj.abc_func(1);
          }
  };
  
  TEST(AbcTest, func_success)
  {
      MockAbc *mock = new MockAbc();
  
      EXPECT_CALL(*mock,  abc_func(_)).WillOnce(Return(true));
  
      Xyz test;
  
      EXPECT_TRUE(test.xyz_func());
  
      delete mock;
  }
  
  int main(int argc, char** argv)
  {
      ::testing::InitGoogleMock(&amp;argc, argv);
      return RUN_ALL_TESTS();
  }
  </code></pre>
  
  <p>But i get the below error. I want to know how we can tell Xyz class to call mock of abc_func instead of actual implementation. Could you please help me.</p>
  
  <pre><code>1 :: ./gmock_test.cpp :: 30
  ./gmock_test.cpp:50: Failure
  Actual function call count doesn't match EXPECT_CALL(*mock, abc_func(_))...
           Expected: to be called once
             Actual: never called - unsatisfied and active
  </code></pre>