I've done what you describe but the basic problem is the test method exits before the
thread has completed.
In the code:
TEST_F(RenderTest, TestRender)
{
MockIListener mockListener;
m_pAppData->addListener(&mockListener);
{
InSequence dummy;
EXPECT_CALL(mockListener, onStartRender(_,_)).Times(1);
EXPECT_CALL(mockListener, onProgress(_,_)).Times(AtLeast(99));
EXPECT_CALL(mockListener, onJobRendered(_,_)).Times(1);
EXPECT_CALL(mockListener, onQueueDepleted()).Times(1);
}
// ... build and init render job
m_pAppData->AddRenderJob(renderJob);
m_pAppData->StartRenderThread();
}
The trouble is StartRenderThread starts a thread and the method exits afterwards. So none
of the expected calls of the mock listener takes place.
The fact that the method dies without waiting for the thread to complete is not-surprising behaviour from gtest / gmock.
I guess I should change the prototype of the method and return the thread handle and wait for it
to complete in the test method.