3

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.

enter image description here

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

GrimSmiler
  • 561
  • 1
  • 4
  • 21
  • Currently i found no solution for this. Given a .net framework project using MSTest V2 you could follow the workaround specified [here](https://developercommunity.visualstudio.com/content/problem/80374/cant-associate-net-framework-unit-test-to-test-cas.html) , but i wasn't able to get it to work on .net core. – GrimSmiler Feb 16 '18 at 13:44
  • You can update the associated automation on a work item via the REST API – Daniel Mann Feb 16 '18 at 18:52
  • @DanielMann thx, gonna check it out. Do you have a link to a manual or the API endpoint by any chance? – GrimSmiler Feb 19 '18 at 09:14

2 Answers2

2

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?

Sebastian Weber
  • 6,766
  • 2
  • 30
  • 49
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • Hey! I did update the test case. When i start the build associated with a test plan, generate the test results and publish them online TFS, the state of the test case does not change. Any idea why? – GrimSmiler Mar 01 '18 at 14:08
  • @GrimSmiler Did you mean you have associated a vNext build with your Test Plan in Microsoft Test Manager, and after the build run, test result published, you want to also change the status of the test case? What's the test case state, spelling mistake? Are you talking about the status of test case such as pass, not run, NA ... – PatrickLu-MSFT Mar 01 '18 at 15:12
  • Yes, i have associated a test plan with a vNext build. [here](https://learn.microsoft.com/en-us/vsts/build-release/test/run-automated-tests-from-test-hub) it says, that updating a state is only possible in Releases, not builds. Yes, i want to change the state of a test run - passed, failed, blocked and etc. – GrimSmiler Mar 01 '18 at 15:35
1

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/

MikeDouglasDev
  • 1,331
  • 10
  • 22