Gtest piling function, gtest piling Function

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.