Search code examples
c++googletest

how to test public void function which calls void private function of the same class using google test


dummy code:

void fun()
{
    while (m->hasMessage())
    {
        std::pair<std::string, Vector> msg_pair = m->getMessage();
        auto topic = msg_pair.first;
        auto msg = msg_pair.second;

        for (auto const& x : msg)
        {
            auto const type = m->MessageType(x);

            if (type == "a")
            {
                funa(x,topic);
            }
            else if (type == "b")
            {
                funb(x,topic);
            }
            
            else if (type == "c")
            {
                func(x,topic);
            }
        }
    }
}

fun a,fun b , fun c are private functions and fun is public function of same class how to test function fun using google test


Solution

  • The approach that I have followed to test public function which in turn calling private function is adding throw conditions(exceptions) in private functions and in test case using macro EXPECT_NOTHROW to test the public function :

    EXPECT_NOTHROW(obj.publicfunction);