1

I am unable to associate test methods to test cases in the Test Explorer (the "Associate to Test Case" option is greyed out), or via MTM, or the VSTS website. I simply cannot find a way to associate tests to the test cases for automated testing.

I am using .NET core app 1.1, ASP.NET using MSTest (though I have tried Xunit as well, to no avail). Even a basic test case that always passes cannot be associated.

In MTM, I have created a test plan that has the Automation Status set to "Plan".

In VSTS, I have a project using a Git repository, in which I have a CI build created that successfully discovers, runs and reports the tests.

I cannot find where to associate these specific tests to test runs. How may I accomplish this?

2 Answers 2

5

Refer to these steps to associate test method to test case:

  1. Install MTM 2017 (Run VS 2017 install app (vs_Enterprise.exe)>Modify)

enter image description here

  1. Open VS 2017>Tools>Options>Work Items>General> Select Visual Studio (Compatibility mode) for Open work items in:

enter image description here

  1. Open your test project in VS 2017 and build
  2. Open Team explorer and connect to your team project
  3. Type test case id in Search Work items box> Press enter to open test case
  4. Select Associated Automation tab and click …
  5. Select a test method > OK
  6. 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();
3
  • Thank you starain! Unfortunately, I have tried updating the associated automation inside VS, but it doesn't show any test methods despite them being visible in the test explorer. Is there anything special I need to set on them for them to be visible? Jun 16, 2017 at 13:33
  • @IanZimmérman AFAIK, Visual Studio will only recognize MSTest v1 tests. The REST API method does work, however. Jun 16, 2017 at 13:41
  • Where in xUnit file do I need to specify the same GUID as in Microsoft.VSTS.TCM.AutomatedTestId field for linking to work?
    – Mak Sim
    May 29, 2019 at 13:30
0

Check this extension that I have created https://github.com/JanuszNowak/janono.ado.testcase.associate.cli . It allows associating in automatic manner. So if yours selenium test are using xunit, nunit or mstest you can associate them automatically.

Code sample:

namespace ExampleTestProject
{
    [TestClass]
    [janono.ado.testcase.associate.Organization("janono-pub")]
    public class UnitTest1
    {
        [TestMethod]
        [janono.ado.testcase.associate.TestCase(5)] //<---
        public void TestMethod1()
        {
            //yours test method content
            //...
            //
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.