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

后端 未结 6 1668
遇见更好的自我
遇见更好的自我 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条回答
  •  时光说笑
    2020-12-28 17:36

    Declare a friend class MyClass_UnitTest; in your MyClass. You can then define MyClass_UnitTest elsewhere in your unit test program that has full access to MyClass internals, but you don't have to provide an implementation in your release application. See CppUnit documentation for a good example of how this is done.

提交回复
热议问题