Reputation: 391
I want to use gmock in my unit tests. I wrote very simple example and it fails. ISymbolTable is interface I want to mock. MockSymbolTable is mocked object. In test I call insert and check if any insert was called.
GMOCK WARNING:
Uninteresting mock function call - returning directly. Function call: insert(8-byte object <24-7C 4C-04 03-00 00-00>) Stack trace: LexerTests.cpp:25: Failure Actual function call count doesn't match EXPECT_CALL(symbolTable, insert(::testing::_))...
class ISymbolTable {
public:
ISymbolTable() {}
virtual ~ISymbolTable() {};
virtual void insert(const Entry entry) = 0;
virtual int lookUp(const std::string text) = 0;
};
class MockSymbolTable : public ISymbolTable {
public:
MOCK_METHOD1(insert, void(const Entry entry));
MOCK_METHOD1(lookUp, int(const std::string text));
};
TEST(Lexer, N) {
MockSymbolTable symbolTable;
symbolTable.insert(Entry("dsgft", 3));
EXPECT_CALL(symbolTable, insert(::testing::_)).Times(1);
}
Upvotes: 3
Views: 8625
Reputation: 1
You have to rewrite the test case as follows
TEST(Lexer, N) {
MockSymbolTable symbolTable;
EXPECT_CALL(symbolTable, insert(::testing::_)).Times(1);
symbolTable.insert(Entry("dsgft", 3));
}
All call expectations must be set up before the mock object is touched first.
Upvotes: 4