I've written a small test with a mocked class. When I run it, first I get the warning that an uninteresting mock function was called and then the test fails because the expectation is not met, which is that the mocked function is called at least once. The funny thing is that that function is called as I see that warning message above.
Do you have any ideas on this matter?
Thank you!
Edit: This is my code structure:
class Bla {
public:
Bla();
virtual ~Bla();
virtual float myFunction();
}
class MockBla : public Bla {
MockBla();
~MockBla();
MOCKMETHOD0(myFunction, float());
}
class CallerClass {
public:
CallerClass() { MockBla* myMock = new MockBla(); }
virtual ~CallerClass();
myCallingFunction() { myMock->myFunction(); }
}
class MyTestClass : public ::testing::Test {
//....
TEST(myTest, testMyFunction) {
MockBla mockBla;
EXPECT_CALL(mockBla, myFunction()).Times(AtLeast(1));
CallerClass* callerClass;
callerClass = new CallerClass();
callerClass->myCallingFunction();
}
//....
}
Result:
[ RUN ] MyTestClass.testMyFunction
GMOCK WARNING:
Uninteresting mock function call - returning default value.
Function call: myFunction()
Returns: 0
Stack trace:
MyTestClass.cpp:99: Failure
Actual function call count doesn't match EXPECT_CALL(mockBla, myFunction())...
Expected: to be called at least once
Actual: never called - unsatisfied and active
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…