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

吃可爱长大的小学妹 提交于 2019-12-07 12:21:02

问题


I am trying to figure out how to associate a Test Case in TFS 2018 to a Xunit Fact in a .Net Core project.
If i click on the XUnit Fact in the Visual Studio 2017 Test Explorer, the association option is disabled.

Does anyone know how to associate a Xunit Fact to a Test Case in TFS?


回答1:


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?




回答2:


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/



来源:https://stackoverflow.com/questions/48825094/how-to-associate-a-xunit-fact-to-a-test-case-in-tfs

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