Why is Private Accessor deprecated?

会有一股神秘感。 提交于 2019-12-22 08:37:52

问题


It used to be the number one reason for us to choose MSTest from others that we could access and test private methods. Now that Private accessors are deprecated in Visual Studio 2012. Does anyone know why Microsoft make such decision? Is it because it's not a good practice to test private methods?

Also, if I still need to unit test my private methods, how could I do that in VS 2012 and later versions?


回答1:


According to VS team article Generation of Private Accessors... this feature was deprecated in 2010 for following reasons:

  1. Lack of resources and time: The focus for this release has been to improve the experience for manual testers, so the priority for the code generation and publicize features has been lowered. There have also been other issues with the publicize functionality that we utilize that have not been addressed.

  2. New features by Language teams: As the language teams have made modifications to their project types and languages, we have been unable to respond to the changes they have made and have not been able to work with the new features they have introduced.

(More historical notes may be found via following search: mstest why private accessors depricated site:blogs.msdn.com ).

For your second part of the question - generally you should not need to unit-test private methods. If you really feel need to expose such methods for testing - consider if marking internal and using "friend" (InternalsVisibleToAttribute) would work for your case.



来源:https://stackoverflow.com/questions/25367731/why-is-private-accessor-deprecated

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