Re: [googlemock: 1645] how to implement the mocked virtual method?

1,133 views
Skip to first unread message

Greg Miller

unread,
Oct 16, 2012, 9:16:17 AM10/16/12
to Jeff Lee, Google C++ Mocking Framework, li.fen...@qq.com



On Mon, Oct 15, 2012 at 10:59 PM, Jeff Lee <hitbla...@gmail.com> wrote:
I am new to gmock,  forgive me for my ignorance

if I have a pure virtual class(interface) A:
//A.hpp
class A
public:
virtual void doSomeThing()  = 0;
}


I want to mock A, and define a mock class mockA:
//mockA.hpp
class mockA
{
public:
    MOCK_METHOD0(doSomeThing,void());
}

Good so far...
 

how I should implement the mocked virtual method? if I put it into seperate cpp file like this:
//mockA.cpp
#include "mockA.hpp"
void mockA::doSomeThing()
{
......
}

is that right?

No. You don't implement the mocked function—gMock does. You then use macros like EXPECT_CALL() to tell the mocked function what to expect and how to behave. 


HTH,
Greg

Jeff Lee

unread,
Oct 22, 2012, 2:59:38 AM10/22/12
to googl...@googlegroups.com, Jeff Lee, li.fen...@qq.com
thank you very much!

I found great examples here



在 2012年10月16日星期二UTC+8下午9时16分19秒,Greg Miller写道:
Reply all
Reply to author
Forward
0 new messages