Compartir a través de


How to access Test Case Manager Test Case ID

In Visual Studio 2010, we can create test cases using Microsoft Test Manager and can associate automation to these test cases. During the test method execution, we might need the test case Id of the test case for various reasons.

Unfortunately, the TESTCONTEXT doesn’t expose the Test Case Management context that you could use from the Test Method itself.

1. Write a custom data collector. This article will help in writing a simple custom data collector - https://blogs.microsoft.co.il/blogs/shair/archive/2010/04/19/how-to-create-custom-datacollector-in-visual-studio-2010-part-1.aspx

2. From the custom data collector's event handler, you could access the Test Case Management Context like below.

private void OnTestCaseStart(object sender, TestCaseStartEventArgs e)

{

      try

      {

           File.WriteAllText(@"C:\MTM_TC_Association\TestCaseID.txt", e.TcmInformation.TestCaseId.ToString());

      }

}