Gtest piling function, gtest piling Function
Assume that the Client is defined as follows:
class Client { ...... public : virtual bool GetData(std::string& data); ...... };
We only need to override the Getdata method. When the parameter data is passed in, we can return a specific value.
Google has provided a good framework for this method: gmock
The following describes its usage.
#include "client.h" // The header file of the mock class #include <gmock gmock.h= "" > // Gmock header file class MockClient : public Client { public : MockClient():Client() {} MOCK_METHOD1(GetData, bool(std::string&)); }</gmock>
A macro MOCK_METHOD1 is used here.
MOCK_METHOD #1 (#2, #3 (#4 ))
#1 indicates the number of function parameters to be mock, #2 indicates the name of the function to be mock, #3 indicates the return value of the function to be mock, and #4 indicates the list of function parameters to be mock.
In this way, a "pile" is better.