GithubHelp home page GithubHelp logo

trantrungtin / googlemock-extension Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 39 KB

Extension for Google Mock

License: MIT License

C++ 85.50% C 0.89% CMake 13.61%
gmock google-mock gtest google-test non-virtual-interface extension

googlemock-extension's Introduction

Extension for Google Mock

Features

  • Support non-virtual methods
  • Same functionality as google mock

Google Mock

Details and examples of Google Mock can be found here:

Use cases

You have some non-virutal methods needed to mock.

class Demo {
 public:
  int add(int a, int b); /* Need to mock this method */
  int mul(int a, int b, int c); /* Need to mock this method */
  virtual int sub(int a, int b);
};

Mock your functions with macro MOCK_METHOD_EX

#include "gmock-extension.h"

class MockDemo : public Demo {
 public:
  MockDemo(){};
  MOCK_METHOD(int, sub, (int a, int b));
  MOCK_METHOD_EX(int, add, (int a, int b)); /* Same style as google mock */
  MOCK_METHOD_EX(int, mul, (int a, int b, int c));
};

Used EXPECT_CALL_EX, ON_CALL_EX to setup your method's behavior.

TEST_F(DemoTest, TestAdd) {
  EXPECT_CALL_EX(*mMock, add(_, _)).WillOnce([] { return 10; });
  EXPECT_EQ(10, mMock->add(2, 3));
}

Checkout examples for more details.

Build

git clone --recurse-submodules https://github.com/trantrungtin/googlemock-extension.git
cd googlemock-extension
mkdir -p build && cd build
cmake .. -DCMAKE_OSX_ARCHITECTURES=arm64 && make && bin/gmocke_examples

googlemock-extension's People

Contributors

trantrungtin avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.