Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid matching .WillOnce multiple times in Google Mock

Tags:

I have a mock object setup that looks like this:

MyObject obj; EXPECT_CALL(obj, myFunction(_)) .WillOnce(Return(1)) .WillOnce(Return(1)) .WillOnce(Return(1)) .WillRepeatedly(Return(-1)); 

Is there a way to not have to repeat .WillOnce(Return(1)) three times?

like image 516
UXkQEZ7 Avatar asked Aug 07 '13 19:08

UXkQEZ7


People also ask

What is Expect_call?

EXPECT_CALL not only defines the behavior, but also sets an expectation that the method will be called with the given arguments, for the given number of times (and in the given order when you specify the order too).

What is Gmock?

Gmock is a mocking framework for the Groovy language. Gmock is all about simple syntax and readability of your tests so you spend less time learning the framework and more writing code. To use Gmock just drop the gmock jar file in your classpath. The current version is gmock-0.8.


Video Answer


1 Answers

using testing::InSequence;  MyObject obj;  {   InSequence s;   EXPECT_CALL(obj, myFunction(_))       .Times(3)       .WillRepeatedly(Return(1));   EXPECT_CALL(obj, myFunction(_))       .WillRepeatedly(Return(-1)); } 
like image 72
VladLosev Avatar answered Oct 04 '22 12:10

VladLosev