'How to return inside gtest?

I am adding couple of tests using google test for the program(C++). For one case, I noticed there is a dependency on database for that test to proceed, so looks like it passes sometimes and failed at other times.

I am thinking of doing something like:

TEST_F(DependentClass, aTest)
{
    if(database is opened successfully)
    {
        // Do the checks here
    }
}

Is it possible to implement something like this for gtest? Or any other way to tackle this issue?

I know mocking the database can be one of the approach, but I'm keeping it as a last solution.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source