如何测试私有函数或具有私有方法,字段或内部类的类?

泪湿孤枕 提交于 2020-08-04 12:06:53

问题:

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!