How do I test private class members without writing FRIEND_TEST()s?
You should try to write testable code, which means classes should be easily tested from their public interface. One way to achieve this is the Pimpl idiom: you move all private members of a class into a helper class, and make all members of the helper class public. You have several other options that don’t require using FRIEND_TEST: • Write the tests as members of the fixture class: class Foo { friend class FooTest; … }; class FooTest : public ::testing::Test { protected: … void Test1() {…} // This accesses private members of class Foo. void Test2() {…} // So does this one. }; TEST_F(FooTest, Test1) { Test1(); } TEST_F(FooTest, Test2) { Test2(); } • In the fixture class, write accessors for the tested class’ private members, then use the accessors in your tests: class Foo { friend class FooTest; … }; class FooTest : public ::testing::Test { protected: … T1 get_private_member1(Foo* obj) { return obj->private_member1_; } }; TEST_F(FooTest, Test1) { … get_private_member1(x)