-
How
GMock
works?-
It's not a C++ standard solution (depends on vtable implementation)
- Itanium C++ ABI (vtable)
- VTable in GCC
- Deleting Destructors
- Devirtualization in C++
- Member Function Pointers and the Fastest Possible C++ Delegates
- Reversing C++ Virtual Functions
- C++ vtables
g++ -fdump-class-hierarchy interface.hpp
-
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)
class example; // System Under Test
GTEST(example) {
namespace di = boost::di;
SHOULD("create example") {
const auto 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();
}
}