用于 WorkItemAttribute?
我注意到 Visual Studio 测试中有一个属性 Microsoft.VisualStudio.TestTools.UnitTesting.WorkItemAttribute 可用(我正在使用 VS 2010 Premium 和 TFS 2010 的工作项。)
使用工作项编号标记测试方法听起来很方便,但确实如此实际上做了什么吗?我根本不知道是否有任何工具支持它。我像这样设置了一个:
[WorkItem(25788)]
[TestMethod]
public void TestSomethingSpecificToABug()
{
...
但没什么神奇的 - 我想也许“测试结果”窗口中测试的上下文菜单可能会提供打开工作项的功能,或者团队资源管理器可能具有搜索测试的功能。 MSDN 文档 也没有帮助。这个属性有什么用呢?
I noticed there's an attribute Microsoft.VisualStudio.TestTools.UnitTesting.WorkItemAttribute available in visual studio testing (I'm using VS 2010 Premium and work items with TFS 2010.)
Marking a test method with a work item number sounds handy, but does it actually do anything? I can't tell if there's any tool support for it at all. I set one up like this:
[WorkItem(25788)]
[TestMethod]
public void TestSomethingSpecificToABug()
{
...
But no magic - I thought maybe the context menu on the test in the Test Results window might offer to open the work item, or Team Explorer might have a feature to search for tests. The MSDN documentation is no help either. What is this attribute good for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
根据“使用 Visual Studio® 2010 进行软件测试”,作者:Jeff Levinson(Addison-Wesley Professional,2011 年 2 月,ISBN-10:0- 321-73448-3):
所以答案是,不要将其与 TFS 2010 一起使用。
According to "Software Testing with Visual Studio® 2010" by Jeff Levinson (Addison-Wesley Professional, February 2011, ISBN-10: 0-321-73448-3):
So the answer is, don't use this with TFS 2010.
WorkItem 测试方法属性不用于将测试方法与测试用例相关联。它通常用于将测试方法与错误关联起来。
代码索引 - 如何发现被忽略的测试:
WorkItem Test Method attribute is not used for associating test methods to test cases. It is typically used to associate a test method with a bug.
A related C# example from Code Index - How to discover ignored tests:
它将单元测试链接回 TFS 中的工作项。我会提供更多信息的链接,但似乎确实没有很好的记录。
我自己没有使用过它,但相信它可以用来生成有关工作项目状态的报告。
It's to link the unit test back to a work item in TFS. I'd provide a link to more info but it seems it really is poorly documented.
I haven't used it myself but believe it can be used to generate reports on the status of work items.
这不再需要:在 VS 2013 中通过 CodeLens
查找链接的工作项 (Alt + 7)
查找链接的代码审查 (Alt + 8)
查找链接的错误(Alt + 9)
要查看测试的定义,请双击测试。
哦!对于那些珍惜 Lync 的人:
联系项目的所有者 (Shift + F10)
This isn´t needed anymore: in VS 2013 via CodeLens
Find linked work items (Alt + 7)
Find linked code reviews (Alt + 8)
Find linked bugs (Alt + 9)
To review a test's definition, double-click the test.
Oh! for those that cherish Lync:
Contact the owner of an item (Shift + F10)
我确实记得,我之前使用过这个属性,并且测试结果已附加到相应的工作项中。
然而,在 Visual Studio 2012 中,它不再起作用,或者我忘记了哪个机制实际上负责了这个魔力。难道这只能通过构建服务器起作用吗?
I really do remember, that I used this Attribute before and the test results have been attached to the respective WorkItem.
However, with Visual Studio 2012, it does not work anymore, or I forgot which mechanism was actually responsible for the magic. Could it be that this only works through the build server?
当您有一个为运行 Selenium UI 单元测试而构建的自制测试工具时,从测试二进制文件中提取属性非常有用。
测试失败后,我可以使用 System.Reflection.MemberInfo.CustomAttributes 提取 WorkItemAttribute 值,然后使用 TFS API 查找 ID。如果工作项是一个错误并且仍然处于活动状态,我可以自动解决该错误的故障。通过这种方式,我可以每天运行失败的测试并自动解决失败以减少随机性。
Pulling attributes from the test binary is really useful when you have a home grown test harness built for running Selenium UI unit tests.
After a test failure, I can pull the WorkItemAttribute value using System.Reflection.MemberInfo.CustomAttributes and then look up the ID with the TFS API. If the work item is a bug and it's still active, I can auto-resolve the failure to that bug. In this manner, I can run the failing test every day and automatically resolve the failure to reduce randomization.