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?
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).
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.
using testing::InSequence; MyObject obj; { InSequence s; EXPECT_CALL(obj, myFunction(_)) .Times(3) .WillRepeatedly(Return(1)); EXPECT_CALL(obj, myFunction(_)) .WillRepeatedly(Return(-1)); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With