What I'm trying to do is set expectations for a function that will be called multiple times but on different function calls. I've tried everything from combinations of EXPECT_CALL and ON_CALL with .WillRepeatedly and .WillByDefault but nothing seems to work.
Currently, I have this:
Mock mock;
EXPECT_CALL(mock, isFoo())
.Times(2)
.WillRepeatedly(Return(false));
SomeClass someClass(mock);
Bar bar;
bar.functionImTesting(someClass);
// Some checks that are passing
bar.functionImTesting(someClass);
// Some more checks that fail because of this problem
Inside functionImTesting(), mock.isFoo() is called once. As I have two calls to functionImTesting(), I have two calls for that function.
This doesn't work. The first call works as expected but on the second one, the default value is issued.
Those are the Warnings:
GMOCK WARNING:
Uninteresting mock function call - returning default value.
Function call: isFoo()
Returns: false
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See http://ift.tt/2cfeJ8y for details.
Actual function call count doesn't match EXPECT_CALL(mock, isFoo())...
Expected: to be called twice
Actual: called once - unsatisfied and active
Ps: Yes. I know I'm setting it to false and the default value is false, so this works. But as you can imagine this is just one occurrence of several in this same test.
BONUS QUESTION
On this same test I need to return 3 different values from three mock calls inside same function I'm testing. As you may recall functionImTesting is called twice so that totals 6 times.
I'm doing this:
EXPECT_CALL(mock, foo())
.Times(6)
.WillOnce(Return(a))
.WillOnce(Return(b))
.WillOnce(Return(c))
.WillOnce(Return(a))
.WillOnce(Return(b))
.WillOnce(Return(c));
Is there a smarter way of doing this that I missed?
Aucun commentaire:
Enregistrer un commentaire