title: How can I create a partial (hybrid) mock in googlemock?
body: <p>Google suggests <a href="https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#delegating-calls-to-a-real-object" rel="noreferrer">delegating calls to a parent object</a> when you need to invoke functionality of the real object, however this does not really create a partial (hybrid) mock. When invoking the real object, any method calls are those of the real object and not the mock object, on which you may have set up actions/expectations. How do I create a partial mock that delegates only specific methods to the real object, and all other method calls to the mock object?</p>
  
  <h3>Delegate to real object example</h3>
  
  <pre><code>using ::testing::_;
  using ::testing::AtLeast;
  using ::testing::Invoke;
  
  class MockFoo : public Foo {
   public:
    MockFoo() {
      // By default, all calls are delegated to the real object.
      ON_CALL(*this, DoThis())
          .WillByDefault(Invoke(&amp;real_, &amp;Foo::DoThis));
      ON_CALL(*this, DoThat(_))
          .WillByDefault(Invoke(&amp;real_, &amp;Foo::DoThat));
      ...
    }
    MOCK_METHOD0(DoThis, ...);
    MOCK_METHOD1(DoThat, ...);
    ...
   private:
    Foo real_;
  };
  ...
  
    MockFoo mock;
  
    EXPECT_CALL(mock, DoThis())
        .Times(3);
    EXPECT_CALL(mock, DoThat("Hi"))
        .Times(AtLeast(1));
    ... use mock in test ...
  </code></pre>