I had to test a function similar with foo():
class A{
.....
void foo(int a)
{
if( nullptr != m_member_name)
m_member_mane->another_function();
else Logger << "some message";
}
.....
Member_name *m_member_name;
}//end class A
In order to have branch coverage I think that I should make one test for m_member_name != nullptr and one for m_member_name == nullptr.
For the first is easy, because I expect that another_function() is called once, using
EXPECT_CALL(MOCK_Member_name, another_function())
.Times(1); // I created a mock for Member_name before
Where MOCK_Member_name is a mock for Member_name
But how should I verify if for m_member_name == nullptr is going on else branch?
I know that is a silly question, but I've only been studying Google Mock for a short time.
I studied more(please see the source and there is the best solution in this specific case.
If i want to verify if I it goes on else branch, I should just expect that the function from if to don't be called at all, using .Times(0);
EXPECT_CALL(MOCK_Member_name, another_function())
.Times(0);
For another detailed topics see: googletest-release-1.8.0-googlemock