Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made mock modifiers inheritable #4689

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Made mock modifiers inheritable #4689

wants to merge 1 commit into from

Conversation

AKJ7
Copy link

@AKJ7 AKJ7 commented Dec 26, 2024

Motivation

For large codebases, it can be very annoying to define Mocks:

class MockFoo {
 public:
  MOCK_METHOD((std::pair<bool, int>), GetPair, ());
  MOCK_METHOD(bool, CheckMap, ((std::map<int, double>), bool));
};

Using such mocks will create Uninteresting Mock functions warnings when any of the mock methods are used.
Possible solutions include implementing EXPECT_CALL for each and every mock methods of this class. This can be very teadious and unnecessary when an actual implementation of the mock methods are not needed.

Alternatively, the NiceMock modifier can be used. This can however create very repetative code (Yes, i know #defines and usings can be used), it would be nice if the modifiers can directly be applied directly to the class definition as so:

class MockFoo: public ::testing::NiceMockable<MockFoo> {
 public:
  MOCK_METHOD((std::pair<bool, int>), GetPair, ());
  MOCK_METHOD(bool, CheckMap, ((std::map<int, double>), bool));
};

This feature is implementated in this pull request and i would be happy if this code can be reviewed and merged.

Do i need to update the gtest/gmock docs?

Thanks.

  • Mock object can be made Strict/Nice/Naggy by inheritance

Copy link

google-cla bot commented Dec 26, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

* Mock object can be made Strict/Nice/Naggy by inheritance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant