问题:
How do I unit test (using xUnit) a class that has internal private methods, fields or nested classes? 如何对具有内部私有方法,字段或嵌套类的类进行单元测试(使用xUnit)? Or a function that is made private by having internal linkage ( static
in C/C++) or is in a private ( anonymous ) namespace? 还是通过内部链接 (在C / C ++中为static
)或在私有( 匿名 )名称空间中使其私有化的函数?
It seems bad to change the access modifier for a method or function just to be able to run a test. 仅仅为了能够运行测试而更改方法或函数的访问修饰符似乎很糟糕。
解决方案:
参考一: https://stackoom.com/question/8zb/如何测试私有函数或具有私有方法-字段或内部类的类参考二: https://oldbug.net/q/8zb/How-do-I-test-a-private-function-or-a-class-that-has-private-methods-fields-or-inner-classes
来源:oschina
链接:https://my.oschina.net/u/4432649/blog/4462138