问题
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