Let's say you have a gRPC interface and several domain classes in your app that rely on that interface. Now you want to implement unit tests for the domain classes. The test suits for each class are split into separate cpp file. In every file, a mock class for the gRPC client class is defined. Mocking only required methods seems a good idea.
ClassFloorTests.cpp
class MockBuildingGrpcClient : public BuildingGrpcClient
{
public:
MockBuildingGrpcClient() : BuildingGrpcClient(nullptr){};
MOCK_METHOD(int, GetFloorList, (), (override));
MOCK_METHOD(int, AddFloor, (string& name), (override));
MOCK_METHOD(int, RemoveFloor, (int id), (override));
};
ClassAppartmentTests.cpp
class MockBuildingGrpcClient : public BuildingGrpcClient
{
public:
MockBuildingGrpcClient() : BuildingGrpcClient(nullptr){};
MOCK_METHOD(int, GetAppartmentList, (), (override));
MOCK_METHOD(int, AddAppartment, (string& name), (override));
MOCK_METHOD(int, RemoveAppartment, (int id), (override));
};
todo: If there is some interest in this topic I might consider adding the output from GDB at the point of Segfault.