2017-10-13 2 views

답변

1

당신은 Google Mock documentation에 따라, 위임 - 투 - 현실 기술을 사용하여이 작업을 수행 할 수 있습니다 :

당신은 당신의 모의가 실제와 같은 행동이 있는지 확인하기 위해 위임 - 투 - 실제 기술을 사용할 수 있습니다 호출의 유효성을 검사하는 기능은 그대로 유지합니다. 다음은 그 예입니다.

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 ... 
관련 문제