2017-10-13 4 views

Antwort

1

Sie können dies erreichen, indem die delegierenden-to-real-Technik, wie pro Google Mock documentation:

Sie die delegierenden-to-real nutzen Technik, um sicherzustellen, dass Ihr Mock das gleiche Verhalten wie die realen hat Objekt unter Beibehaltung der Fähigkeit, Anrufe zu validieren. Hier ein Beispiel:

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(&real_, &Foo::DoThis)); 
    ON_CALL(*this, DoThat(_)) 
     .WillByDefault(Invoke(&real_, &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 ... 
Verwandte Themen