用于 WorkItemAttribute?

发布于 2024-12-04 00:09:19 字数 572 浏览 0 评论 0原文

我注意到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

野の 2024-12-11 00:09:19

根据“使用 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):

This also means that one existing property should not be used anymore:
Associated Work Items. This value is not reported to the data
warehouse and therefore cannot be used for reporting. If you currently
use this property, consider associating your test with an actual Test
Case work item type.

So the answer is, don't use this with TFS 2010.

半透明的墙 2024-12-11 00:09:19

WorkItem 测试方法属性不用于将测试方法与测试用例相关联。它通常用于将测试方法与错误关联起来。
代码索引 - 如何发现被忽略的测试:

当使用 MSTest 构建单元测试套件时,您可以使用
属性 [Ignore] 告诉 MSTest 引擎不要运行测试
评论它。您还可以使用属性 [WorkItem(id)] 来
将单元测试链接到错误数据库(例如 TFS)项,以便您
可以追踪为什么特定测试被标记为忽​​略:

    [Ignore]
    [WorkItem(12345)] // bug 12345 describes why this test was ignored 
    [TestMethod]
    public void IgnoredButWithWorkItemTest()
    {
        //The actual code is not important;  
    }

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:

When using MSTest to build your suite of unit tests, you can use the
attribute [Ignore] to tell the MSTest engine not to run a test instead
of commenting it. You may also use the attribute [WorkItem(id)] to
link the unit test to a bug database (such as TFS) item, so that you
can trace why a particular test has been marked as ignored:

    [Ignore]
    [WorkItem(12345)] // bug 12345 describes why this test was ignored 
    [TestMethod]
    public void IgnoredButWithWorkItemTest()
    {
        //The actual code is not important;  
    }
巾帼英雄 2024-12-11 00:09:19

它将单元测试链接回 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.

_失温 2024-12-11 00:09:19

这不再需要:在 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)

enter image description here

Find linked code reviews (Alt + 8)

enter image description here

Find linked bugs (Alt + 9)

enter image description here

To review a test's definition, double-click the test.

enter image description here

Oh! for those that cherish Lync:

Contact the owner of an item (Shift + F10)

enter image description here

戒ㄋ 2024-12-11 00:09:19

我确实记得,我之前使用过这个属性,并且测试结果已附加到相应的工作项中。

然而,在 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?

鲜血染红嫁衣 2024-12-11 00:09:19

当您有一个为运行 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文