How to associate a XUnit Fact to a Test Case in TFS

人盡茶涼 提交于 2019-12-05 22:43:08
PatrickLu-MSFT

There is a Rest API could update work item filed.

For example:

PATCH https://servername:8080/tfs/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();

Take a look at this similar question How do I associate test methods to test cases?

The ability to associate xUnit test cases is finally available from the Test Explorer in the latest version of Visual Studio 2017 15.7.1. Here is more information on this and includes information on reporting and executing of the tests from a build or release. http://www.deliveron.com/blog/test-case-association-xunit-nunit-and-mstestv2-tests-available-visual-studio-2017-1571/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!