title: How to use GMock check base class function is called
body: <p>This is very closely related to <a href="https://stackoverflow.com/questions/25487301/how-to-use-gmock-to-test-that-a-class-calls-its-base-class-methods">How to use gmock to test that a class calls it&#39;s base class&#39; methods</a> but I'm struggling to get this working with my example.</p>
  
  <p>I'm using GTest and GMock to test drive a new feature so I have a base class...</p>
  
  <pre><code>class SimpleObject
  {
  public:
      explicit SimpleObject() {}
  
      virtual void moveX(int dX)
      {
          // Do important stuff like updating position, bounding box etc.
      }
  
      // ...
  };
  </code></pre>
  
  <p>Based on other TDD I have a derived class and the new feature is such that when I call moveX on the derived object it will do something specific, however it also needs to do the important stuff in SimpleObject::moveX.</p>
  
  <p>I already have test driven unit tests related to the SimpleObject::moveX function so I don't want to repeat them for the derived class. As long as I know SimpleObject::moveX is called then everything's hunky dory.</p>
  
  <p>Anyway, based on the above link and following TDD I've ended up with the following.</p>
  
  <p>The derived class:</p>
  
  <pre><code>    class ComplexObject : public SimpleObject
      {
      public:
          virtual void moveX(int dX)
          {
              // Do something specific
          }
      };
  </code></pre>
  
  <p>The 'testable' class:</p>
  
  <pre><code>class TestableComplexObject : public ComplexObject
  {
  public:
      MOCK_METHOD1(moveX, void(int dX));
  
      void doMoveX(int dX)
      {
          SimpleObject::moveX(dX);
      }
  };
  </code></pre>
  
  <p>The test:</p>
  
  <pre><code>TEST_F(ATestableComplexObject, CallsBaseClassMoveXWhenMoveXIsCalled)
  {
      int dX(8);
      TestableComplexObject obj;
  
      EXPECT_CALL(obj, moveX(dX))
                  .Times(1)
                  .WillRepeatedly(testing::Invoke(&amp;obj, &amp;TestableComplexObject::doMoveX));
  
      obj.moveX(dX);
  }
  </code></pre>
  
  <p>If I run my tests then everything passes. This isn't correct because as you can see ComplexObject::moveX doesn't do anything.</p>
  
  <p>Also, regardless of what I put in doMoveX (which I thought was meant to set up my expectations) the tests will still pass.</p>
  
  <p>I'm obviously missing something simple here, so any ideas?</p>