How do you unit test private methods?

前端 未结 30 1836
无人及你
无人及你 2020-11-22 06:44

I\'m building a class library that will have some public & private methods. I want to be able to unit test the private methods (mostly while developing, but also it coul

30条回答
  •  轮回少年
    2020-11-22 07:28

    You could generate the test method for the private method from Visual studio 2008. When you create a unit test for a private method, a Test References folder is added to your test project and an accessor is added to that folder. The accessor is also referred to in the logic of the unit test method. This accessor allows your unit test to call private methods in the code that you are testing. For details have a look at

    http://msdn.microsoft.com/en-us/library/bb385974.aspx

提交回复
热议问题