google / google/googletest

Feature Request - Change the behaviour of a mock at runtime

Open
#2,131 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
39.5k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

Currently mocks may either be Strict, Naggy or Nice. This change the outcome of the tests, regarding the presence or not of unexpected calls.

In some scenarios, you want to test an object in a particular state. During this initialization phase, the object may call a lot of methods on your mock objects, for which you don’t care (they’re part of other tests). So the mock should be nice at this point, to avoid polluting logs. However, when the actual tests run, you may want it to be strict (i do). And you may want it to be Nice again at cleanup time.

The ```::testing::XXXXUninterestingCalls``` methods could be used to switch the behaviour, but they are not exposed to the user.

I’m proposing to add a new mock type (FickleMock might be a good name), which is Naggy by default, and exposes three additional methods: ```Nice()```, ```Naggy()``` and ```Strict()``` which switches to the respective behaviour.

PR coming soon.

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing Nice, Naggy, and Strict mock behavior and the ::testing::XXXXUninterestingCalls methods named in the issue. Compare how those behaviors are exposed, then define coverage for runtime switching between all three modes; done means the proposed mock can change modes during initialization, testing, and cleanup.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.