I have a test case in MTM named 'myTestCase'. I also have a unit test code (c#) which is corresponding to 'myTestCase'. Adding associated automation in MTM could be done manually, but is there any way by which I could use some code so that the 'Associated Automation' will be added? In other words, i need a code that will connect the unittest code with the Test case in MTM, so that I don't need to link it manually. Sorry, if this sounds dumb. Thank you for the help!
How to add associated automation in MTM through code
685 Views Asked by Pranav At
2
There are 2 best solutions below
0

Thank you @chief7, it helped me solve my query.
For those facing with the same proble, the above mentioned link will help you. I'm posting the code snippet.
This will help in adding the associated automation to the testcase. The required details are automation testname (should be in the format Projectname.Namespace.functionname, eg. Unittest1.Mynamespace.Myfunction) , automation test type, (eg. Unittest) , and automation storage name eg.(UnitTestProject1.dll)
SHA1CryptoServiceProvider crypto = new SHA1CryptoServiceProvider();
byte[] bytes = new byte[16];
Array.Copy(crypto.ComputeHash(Encoding.Unicode.GetBytes(automationTestName)), bytes, bytes.Length);
Guid automationGuid = new Guid(bytes);
testCase.Implementation = testCase.Project.CreateTmiTestImplementation(
automationTestName, automationTestType,
automationStorageName, automationGuid);
testCase.Save();
You could use the TFS API to programmatically set the automation.