Reputation: 900
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.
Upvotes: 2
Views: 2512
Reputation: 2848
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
//...
//
}
}
}
Upvotes: 1
Reputation: 51153
Test Result is also a kind of work item.
Thus you could use Rest API to handle this.
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:
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:
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.
Upvotes: 1