How do I unit test a protected method in C++?

后端 未结 6 1704
遇见更好的自我
遇见更好的自我 2020-12-28 16:57

How do I unit test a protected method in C++?

In Java, I\'d either create the test class in the same package as the class under test or create an anonymous subcla

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 17:34

    There's a simple solution in C++ using #define. Just wrap the include of your "ClassUnderTest" like this:

    #define protected public
     #define private   public
        #include 
     #undef protected
    #undef private
    

    Credit goes to this article and RonFox

提交回复
热议问题