How to make google-test classes friends with my classes?

前端 未结 4 972
别那么骄傲
别那么骄傲 2021-02-01 01:48

I heard there is a possibility to enable google-test TestCase classes friends to my classes, thus enabling tests to access my private/protected members.

How to accomplis

4条回答
  •  一向
    一向 (楼主)
    2021-02-01 01:59

    I know this is old but I was searching for the same answer today. "gtest_prod.h" just introduces a simple macro to reference test classes.

    #define FRIEND_TEST(test_case_name, test_name)\
    friend class test_case_name##_##test_name##_Test
    

    So FRIEND_TEST(FooTest, BarReturnsZeroOnNull); is equivalent to:

    friend class FooTest_BarReturnsZeroOnNull_Test;
    

    This works because each test is its own class as mentioned in the previous answer.

提交回复
热议问题