1

Since I learnt to use Google Test/Mock framework, I allways used the form to setup an expectation as following:

EXPECT_CALL( mock_obj, mock_method ).WillOnce( Invoke( []() { do_things; } ) );

Few days ago, I found that another form also can work as this:

EXPECT_CALL( mock_obj, mock_method ).WillOnce( []() { do_things; } );

My question is:

  1. Is there any difference between those two forms?
  2. When should I use one over another?

Thanks!

1 Answer 1

1

You have to use Invoke with some older versions of googletest (gtest/gmock) library - probably before 1.10.

Now it is mostly obsolete.

There are other Invoke* actions - see https://google.github.io/googletest/reference/actions.html#using-a-function-functor-or-lambda-as-an-action. Still any of these Invoke* are replaceable by custom lambdas - but why to do it if e.g. InvokeWithoutArgs(f) exists. I mean no point to replace InvokeWithoutArgs(f) with [](auto&&...) { f(); }

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.