Previously I would use:
TestContext.Properties["__Tfs_TestRunId__"]
to get the current Id of the run that is executing a specific test case. But in 2017 that doesn't seem to be the case as it is returning an invalid number.
By using the following code I was able to dump the keys of TestContext and it looks like that parameter is no longer present..
private static IEnumerable<DictionaryEntry> SafeCast(IDictionary dictionary)
{
foreach (DictionaryEntry entry in dictionary)
{
yield return entry;
}
}
var dict = new Dictionary<string, string>();
var dictionaryEntries = SafeCast(TestContext.Properties).Select(_ => new { Key = _.Key.ToString(), _.Value }).ToArray();
using (StreamWriter file = new StreamWriter("dump.txt"))
{
foreach (var entry in dictionaryEntries)
{
file.WriteLine("[{0} {1}]", entry.Key, entry.Value);
var outputString = string.Format("[{0} {1}]", entry.Key, entry.Value);
Trace.WriteLine(outputString);
}
}
These are the current keys:
ResultsDirectory
AgentId
AgentName
TestRunDirectory
ControllerName
DataCollectionEnvironmentContext
TestResultsDirectory
TestLogsDir
TestDeploymentDir
TestRunResultsDirectory
TestDir
AgentLoadDistributor
DeploymentDirectory
TotalAgents
TotalAgents
FullyQualifiedTestClassName
TestName
Is there a way that I can force the Run Id to be passed through the TestContext or any other ways I can get the current Run Id?
You can't get test run 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
Similar case: How to retrieve a Test Case ID that is currently running through TFS (vNext) build?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.