Reputation: 1307
I have a unit test project for client side (angular) application written using jasmine framework.
In C# unit test projects, there is a possibility to link each test method with a test case in visual studio test explorer.
Since it's not possible to achieve the same for test methods/suites in unit test project for client side (angular) application which is written using jasmine framework, I was looking at the possibility of creating a tool to create test cases in VSTS by programming. And to map each client side unit test method to a test case in VSTS.
Can anyone help me with the API's and idea on how this can be done?
Upvotes: 1
Views: 1409
Reputation: 33708
Using REST API to do it:
Patch https://[account].visualstudio.com/DefaultCollection/_apis/wit/workitems/[testcaseid]?api-version=1.0
Content-Type: application/json-patch+json
Body:
[
{
"op": "add",
"path": "/fields/Microsoft.VSTS.TCM.AutomatedTestName",
"value": "[namespace.classname.methodname (e.g. UnitTestProject1.UnitTest1.TestMethod2)]"
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.TCM.AutomatedTestStorage",
"value": "[assembly name(e.g. unittestproject1.dll)"
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.TCM.AutomatedTestId",
"value": "[guid id]"
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.TCM.AutomatedTestType",
"value": "Unit Test"
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.TCM.AutomationStatus",
"value": "Automated"
}
]
The AutomatedTestId is a Guid value, so you can generate a new Guid by using this C# code:
Guid g = Guid.NewGuid();
string s = g.ToString();
Refer to How do I associate test methods to test cases?
Upvotes: 2
Reputation: 114741
The REST API for Test Management is pretty extensive and documented clearly over at the VSTS documentation website.
The API is separated into two parts:
Upvotes: 2