问题
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!
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/42843920/how-to-retrieve-a-test-case-id-that-is-currently-running-through-tfs-vnext-bui