Google Mocking: Test fails(should pass?)

Hello,

I just started using Gtest/Gmocks and I'm struggling with an example. I have a simple class which has a member a function that returns a value(say 3). I'm trying to mock this test and check if the returned result is 3. For simplicity I wrote everything in a single file:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Testing.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "gmock\gmock.h"
#include "gtest\gtest.h"
using ::testing::AtLeast;
using namespace std;

class MyClass{
public:
	virtual int retValue() { return 3; } 
	virtual ~MyClass(){}
};


class FakeMyClass : public MyClass
{
public:
	MOCK_METHOD0( retValue, int() );
};

TEST(TestForMyClass, TestRetVal)
{
	FakeMyClass obj3;
	EXPECT_EQ(obj3.retValue(), 3);
}

int _tmain(int argc, _TCHAR* argv[])
{
	::testing::InitGoogleMock(&argc, argv);
	return RUN_ALL_TESTS();
}


However my test fails and it says that expected result is 3 and my actual result is 0.
I've watched a couple of examples and I think I did everything as shown in there still the result is not what I'm expecting. Please help me see where I'm wrong and how can I make that test to pass. Thank you.


Topic archived. No new replies allowed.