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

前端 未结 4 979
别那么骄傲
别那么骄傲 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 02:08

    A far better strategy is to not allow friend tests among your unit tests.

    Allowing friend tests accessing private members will lead to a code base that is hard to maintain. Tests that break whenever a component's inner implementation details are refactored is not what you want. If extra effort is instead put into getting a design where components can be tested through their public interface, you will get tests that only need updating whenever the public interface of a component is updated.

    Tests relying on gtest/gtest_prod.h should be seen as a sign of poor design.

提交回复
热议问题