How to retrieve a Test Case ID that is currently running through TFS (vNext) build?

1.2k views Asked by At

In TFS 2013 when running tests from MTM, we were able to get the ID of the currently running test case by using the TestContext Properties dictionary as follows:

var testCaseID = TestContext.Properties["__Tfs_TestCaseId__"].ToString();

This statement returns NULL if tests are being run as part of TFS vNext build (BDT).

In order to update some fields in test results for instance Comments/Notes, I will need to know the ID of the current test run and test case. How can I return that information?

I am using TFS 2017 on-premise.

Thanks!

2

There are 2 answers

4
starian chen-MSFT On

You can’t get test case id in test method as running test through MTM when run tests during the build (Functional test).

The Workaround is that you can specify the value in runsettings and get the value during test.

More information, you can refer to Supplying Run Time Parameters to Tests

0
user1466508 On

It is possible to get the Test Case Identifier while test is running in TestMethod. You can get it by querying TFS using TFS API. You can do that from your C# code by finding the test results object for current running test case run. You will get the current test run ID from the testContext.