Refer to these steps to associate test method to test case:
- Install MTM 2017 (Run VS 2017 install app (vs_Enterprise.exe)>Modify)
- Open VS 2017>Tools>Options>Work Items>General> Select Visual Studio (Compatibility mode) for Open work items in:
- Open your test project in VS 2017 and build
- Open Team explorer and connect to your team project
- Type test case id in Search Work items box> Press enter to open test case
- Select Associated Automation tab and click …
- Select a test method > OK
- Save test case work item
Another way is that you can associate the test method with test case through Update a field REST API.
For example:
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();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…