为什么不推荐使用专用访问器? [英] Why is Private Accessor deprecated?

查看:86
本文介绍了为什么不推荐使用专用访问器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去,这是我们选择其他可以访问和测试私有方法的MSTest的首要原因.现在,在Visual Studio 2012中不建议使用私有访问器.有谁知道微软为什么要做出这样的决定?是因为测试私有方法不是一个好习惯吗?

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?

此外,如果我仍然需要对私有方法进行单元测试,我该如何在VS 2012和更高版本中做到这一点?

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

推荐答案

根据VS团队文章

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

  1. 缺乏资源和时间:此版本的重点是改善手动测试人员的体验,因此降低了代码生成和发布功能的优先级.我们利用的宣传功能还存在其他尚未解决的问题.

  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.

语言团队的新功能:由于语言团队已对其项目类型和语言进行了修改,因此我们无法响应他们所做的更改,因此无法与他们引入的新功能一起使用.

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 ).

对于问题的第二部分-通常,您不需要对私有方法进行单元测试.如果您确实需要公开此类测试方法,请考虑是否标记internal并使用"friend"(

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.

这篇关于为什么不推荐使用专用访问器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆