Definition not found for MOCK_METHOD*

408 views
Skip to first unread message

Nikita Verma

unread,
Jun 20, 2016, 10:37:37 AM6/20/16
to Google C++ Mocking Framework
Hi All,

I am using Visual Studio 2015 and this is my first test case with gmock. 

I am getting error:
Definition for MOCK_METHOD2() not found.

Please provide the solution.

This is the code:
#include <stdafx.h>
#include<gmock/gmock.h>
#include<gtest/gtest.h>

#include <iostream>

using ::testing::_;
using ::testing::Invoke;
using ::testing::AtLeast;

class CBasicMath
{
public:
CBasicMath() {}
virtual int Addition(int x, int y) {
return x + y;
}
};

class BasicMathTest : public::testing::Test {
protected:
CBasicMath *mTestObj;

BasicMathTest() {
mTestObj = new CBasicMath();
}

virtual ~BasicMathTest()
{
delete mTestObj;
}
};

class MockBasicTest : public CBasicMath
{
public:
MOCK_METHOD2(Addition, int(int x, int y));

MockBasicTest() {
ON_CALL(*this, Addition(_, _)).WillByDefault((Invoke(&real_, &CBasicMath::Addition)));
}
private:
CBasicMath real_;

};

TEST_F(BasicMathTest, testAddition)
{
MockBasicTest basictest;
EXPECT_CALL(basictest, Addition(2, 3)).Times(1);
//EXPECT_EQ(5, &basictest.Addition);
//EXPECT_EQ(5, mTestObj->Addition(2, 3));
}

int main(int argc, char* argv[])
{
testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();

}


Thanks in Advance !!!

Regards,
Nikita 


Reply all
Reply to author
Forward
0 new messages