How
GMockworks?It's not a C++ standard solution (depends on vtable implementation)
Similar projects (FakeIt, HippoMocks)
How quick is
GMock?Compile time benchmark (Example)
Compiler Number of Mocks GoogleMock/GoogleTest GoogleMock/GoogleTest + GUnit GCC-6 3 2.6s 2.1s Clang-3.9 3 2.3s 1.9s
But virtual function call has performance overhead?
- This statement is not really true anymore with modern compilers as most virtual calls might be inlined
Limitations
- GMock can't mock classes with multiple or virtual inheritance
- GMock, by default, can fake interface with up to 128 virtual methods
Integration tests with Dependency Injection ([Boost].DI)
classexample; // System Under TestGTEST(example) {
namespacedi= boost::di;
SHOULD("create example") {
constauto injector = di::make_injector(
di::bind<interface>.to(di::NiceGMock{mocks})
, di::bind<interface2>.to(di::StrictGMock{mocks})
);
sut = testing::make<SUT>(injector);
EXPECT_CALL(mock<interface>(), (get)(_)).WillOnce(Return(123));
EXPECT_CALL(mock<interface2>(), (f2)(123));
sut->update();
}
}