2

I have read through the docs, but I still cannot figure out how a custom Azure DevOps task can associate a test result with a work item programmatically. I built a custom task that executes tests (running and executing outside Azure DevOps). When the tests finish and the results come back, I get the list of associated work items as well. I would like to call the appropriate Azure DevOps API to associate the test result with one or more work items. Any pointers would be welcome.

Bertold Kolics
  • 892
  • 6
  • 11
  • Does this answer your question? [How to add work item as child to parent?](https://stackoverflow.com/questions/50518798/how-to-add-work-item-as-child-to-parent) – Matt Oct 27 '20 at 22:52

2 Answers2

1

Test Result is also a kind of work item.

Thus you could use Rest API to handle this.

  1. Use the Get Test Results REST API to get the test case from the test result that you want to link to the work item:

  2. Use the Get Work Item REST API to get the existing relations of the work item (user story, task, etc) that you'd like to link to the test result, and determine if the test result and/or test case are already linked to the work item:

  3. Uses the Update Work Item REST API to link the test result and/or test case to the work item:

More details of the sample and code snippet please refer Tanyan Harmon's comment in this related user voice: Need ability to link Test Results back to ANY work item type, especially User Stories

You could also follow the link shared by Matt in the comment.

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • Thank you! I have a chicken and egg problem. I developing a Pipeline task that writes out test results using the azure-pipelines-task-lib/task library. Excerpts: tp = new task.TestPublisher('JUnit'); tp.publish(...) How do I get all the parameters needed on the above REST API calls? The examples in the task docs do not go into this detail. – Bertold Kolics Oct 29 '20 at 20:44
  • 1
    @BertoldKolic In your situation, instead of Rest API, Kindly check if this helps: https://oshamrai.wordpress.com/2019/04/04/azure-devops-rest-api-16-create-test-results-linked-to-a-test-plan/ – PatrickLu-MSFT Oct 30 '20 at 10:57
1

Check this extension that I have created https://github.com/JanuszNowak/janono.ado.testcase.associate.cli it allows associating in automatic manner. Code sample:

namespace ExampleTestProject
{
    [TestClass]
    [janono.ado.testcase.associate.Organization("janono-pub")]
    public class UnitTest1
    {
        [TestMethod]
        [janono.ado.testcase.associate.TestCase(5)] //<---
        public void TestMethod1()
        {
            //yours test method content
            //...
            //
        }
    }
}
Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36