Skip to content

Uninteresting call to ON_CALL method #2078

Open
@LiSongMWO

Description

@LiSongMWO

I have read https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#knowing-when-to-expect and understand and agree with the motivation behind uninteresting calls.

However, even though I have added an ON_CALL(Foo, Bar).WillByDefault(Return()); I get a uninteresting mock function call warning. The call to Foo.Bar() is clearly not uninteresting as it is mentioned in the test, the call is allowed (and expected) but not verified and thus I believe it should not emit a warning.

Consider code under test like so:

class UserDatabase{
public:
    UserDatabase(SQLBackend* sql, const std::string& uri, int usersCached){
        sql.connect(uri);
        if(maxUsersCached > MAX_CACHE_SIZE){
             m_users_cached = MAX_CACHE_SIZE;
        } else {
            m_users_cached = usersCached;
        }
    }

Having small concise tests that test specific cases is best practice for testing. Hence I would like some cases that test the connection aspect, and some test cases that test the limiting of the cache size. The former would just use EXPECT_CALL, the latter doesn't care about the connect call but should allow it without warnings. Because warnings are bad. I can use NiceMock but then I loose the benefits intended by the default behaviour of uninteresting calls in all my tests. I can add EXPECT_CALL to the the tests on user cache size but this too is against the recommendations as it adds an unnecessary constraint that is not verified in that test case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions