Hi Neha,
The way I've typically seen mocks used is when implementing dependency injection. So in your case, it would be when you are testing an object that uses a UTManager; something like:
class TestedObject {
TestedObject(Element* ut_manager);
...
}
In your production code, you would pass a real UTManager:
...
TestedObject tested_object(new UTManager);
...
Then, in the test infrastructure, you would pass the mock version:
TEST_F(myTest, foo) {
TestedObject tested_object(new MockElement);
...
}
However, it could be that what you actually need to do in this case is change UTManager so that the dependency or dependencies represented by 'Element' is dependency-injected rather than a base class;
class UTManager {
UTManager(Element* element);
...
private:
Element* element_;
}
Then your test would be something like:
TEST_F(TestElementMock, TEST_StartTimer)
{
MockElement* mockElement = new MockElement();
EXPECT_CALL(*mockElement, StartTimer(_,_,_))
.Times(AtLeast(1));
UTManager* pUTManager = new UTManager(mockElement);
pUTManager->Initialize();
pUTManager->HandleTimeout(12);
delete mockElement;
}
Cheers,
Tyler
--
Tyler Ross | Software Engineer | Google - Apps - Postini