Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use for WorkItemAttribute?

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?

like image 286
James Orr Avatar asked Sep 09 '11 19:09

James Orr


4 Answers

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.

like image 56
John Saunders Avatar answered Oct 31 '22 17:10

John Saunders


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;  
    }
like image 24
user2029971 Avatar answered Oct 31 '22 18:10

user2029971


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.

like image 1
TheCodeKing Avatar answered Oct 31 '22 18:10

TheCodeKing


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

like image 1
Ahmed Alejo Avatar answered Oct 31 '22 18:10

Ahmed Alejo