What is the best way of testing private methods with GoogleTest? [closed]
I would like to test some private methods using GoogleTest. class Foo { private: int bar(...) } GoogleTest allows a couple of ways of doing this. OPTION 1 With FRIEND_TEST : class Foo { private: FRIEND_TEST(Foo, barReturnsZero); int bar(...); } TEST(Foo, barReturnsZero) { Foo foo; EXPECT_EQ(foo.bar(...), 0); } This implies to include "gtest/gtest.h" in the production source file. OPTION 2 Declare a test fixture as a friend to the class and define accessors in the fixture: class Foo { friend class FooTest; private: int bar(...); } class FooTest : public ::testing::Test { protected: int bar(...)