c++ - gmock ignore "interesting" function call -



c++ - gmock ignore "interesting" function call -

i want utilize gmock in unit tests. wrote simple illustration , fails. isymboltable interface want mock. mocksymboltable mocked object. in test phone call insert , check if insert called.

gmock warning:

uninteresting mock function phone 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 phone 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); }

you have rewrite test case follows

test(lexer, n) { mocksymboltable symboltable; expect_call(symboltable, insert(::testing::_)).times(1); symboltable.insert(entry("dsgft", 3)); }

all phone call expectations must set before mock object touched first.

c++ unit-testing mocking gmock

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -