in src/vstest.console/Internal/ConsoleLogger.cs [513:639]
private void TestResultHandler(object sender, TestResultEventArgs e)
{
ValidateArg.NotNull(sender, nameof(sender));
ValidateArg.NotNull(e, nameof(e));
var testDisplayName = e.Result.DisplayName;
if (string.IsNullOrWhiteSpace(e.Result.DisplayName))
{
testDisplayName = e.Result.TestCase.DisplayName;
}
string formattedDuration = GetFormattedDurationString(e.Result.Duration);
if (!string.IsNullOrEmpty(formattedDuration))
{
testDisplayName = string.Format("{0} [{1}]", testDisplayName, formattedDuration);
}
var executionId = GetExecutionId(e.Result);
var parentExecutionId = GetParentExecutionId(e.Result);
if (parentExecutionId != Guid.Empty)
{
// Not checking the result value.
// This would return false if the id did not exist,
// or true if it did exist. In either case the id is not in the dictionary
// which is our goal.
LeafTestResults.TryRemove(parentExecutionId, out _);
}
if (!LeafTestResults.TryAdd(executionId, new MinimalTestResult(e.Result)))
{
// This would happen if the key already exists. This should not happen, because we are
// inserting by GUID key, so this would mean an error in our code.
throw new InvalidOperationException($"ExecutionId {executionId} already exists.");
}
switch (e.Result.Outcome)
{
case TestOutcome.Skipped:
{
if (VerbosityLevel == Verbosity.Quiet)
{
break;
}
// Pause the progress indicator before displaying test result information
_progressIndicator?.Pause();
Output.Write(string.Format("{0}{1} ", TestResultPrefix, CommandLineResources.SkippedTestIndicator), OutputLevel.Information, ConsoleColor.Yellow);
Output.WriteLine(testDisplayName, OutputLevel.Information);
if (VerbosityLevel == Verbosity.Detailed)
{
DisplayFullInformation(e.Result);
}
// Resume the progress indicator after displaying the test result information
_progressIndicator?.Start();
break;
}
case TestOutcome.Failed:
{
if (VerbosityLevel == Verbosity.Quiet)
{
break;
}
// Pause the progress indicator before displaying test result information
_progressIndicator?.Pause();
Output.Write(string.Format("{0}{1} ", TestResultPrefix, CommandLineResources.FailedTestIndicator), OutputLevel.Information, ConsoleColor.Red);
Output.WriteLine(testDisplayName, OutputLevel.Information);
DisplayFullInformation(e.Result);
// Resume the progress indicator after displaying the test result information
_progressIndicator?.Start();
break;
}
case TestOutcome.Passed:
{
if (VerbosityLevel == Verbosity.Normal || VerbosityLevel == Verbosity.Detailed)
{
// Pause the progress indicator before displaying test result information
_progressIndicator?.Pause();
Output.Write(string.Format("{0}{1} ", TestResultPrefix, CommandLineResources.PassedTestIndicator), OutputLevel.Information, ConsoleColor.Green);
Output.WriteLine(testDisplayName, OutputLevel.Information);
if (VerbosityLevel == Verbosity.Detailed)
{
DisplayFullInformation(e.Result);
}
// Resume the progress indicator after displaying the test result information
_progressIndicator?.Start();
}
break;
}
default:
{
if (VerbosityLevel == Verbosity.Quiet)
{
break;
}
// Pause the progress indicator before displaying test result information
_progressIndicator?.Pause();
Output.Write(string.Format("{0}{1} ", TestResultPrefix, CommandLineResources.SkippedTestIndicator), OutputLevel.Information, ConsoleColor.Yellow);
Output.WriteLine(testDisplayName, OutputLevel.Information);
if (VerbosityLevel == Verbosity.Detailed)
{
DisplayFullInformation(e.Result);
}
// Resume the progress indicator after displaying the test result information
_progressIndicator?.Start();
break;
}
}
}