Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the normal verbosity level to not log the full information for non-failed tests #1396

Merged
merged 10 commits into from
Feb 1, 2018
136 changes: 82 additions & 54 deletions src/vstest.console/Internal/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ internal enum Verbosity
{
Quiet,
Minimal,
Normal
Normal,
Detailed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add detailed to help for customer to aware this option.

}

#region Fields
Expand All @@ -76,7 +77,6 @@ internal enum Verbosity
private Verbosity verbosityLevel = Verbosity.Minimal;
#endif

private TestOutcome testOutcome = TestOutcome.None;
private int testsTotal = 0;
private int testsPassed = 0;
private int testsFailed = 0;
Expand Down Expand Up @@ -142,9 +142,9 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory)
}

// Register for the events.
events.TestRunMessage += this.TestMessageHandler;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have been following this convention to use 'this' with members, makes it readable, any specific reason why we are removing it ?

events.TestResult += this.TestResultHandler;
events.TestRunComplete += this.TestRunCompleteHandler;
events.TestRunMessage += TestMessageHandler;
events.TestResult += TestResultHandler;
events.TestRunComplete += TestRunCompleteHandler;
}

public void Initialize(TestLoggerEvents events, Dictionary<string, string> parameters)
Expand All @@ -171,7 +171,7 @@ public void Initialize(TestLoggerEvents events, Dictionary<string, string> param
bool.TryParse(prefix, out ConsoleLogger.AppendPrefix);
}

this.Initialize(events, String.Empty);
Initialize(events, String.Empty);
}
#endregion

Expand Down Expand Up @@ -337,7 +337,6 @@ private void TestMessageHandler(object sender, TestRunMessageEventArgs e)
Output.Warning(ConsoleLogger.AppendPrefix, e.Message);
break;
case TestMessageLevel.Error:
this.testOutcome = TestOutcome.Failed;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is removed? This impact behavior. If the adapter/platform send any error message after this change we not failing test run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix this and add an UT. Currently didn't see any UT fail.. Also why is the failure of a run decided at a logger level ?

Output.Error(ConsoleLogger.AppendPrefix, e.Message);
break;
default:
Expand All @@ -355,53 +354,82 @@ private void TestResultHandler(object sender, TestResultEventArgs e)
ValidateArg.NotNull<TestResultEventArgs>(e, "e");

// Update the test count statistics based on the result of the test.
this.testsTotal++;
testsTotal++;

string name = null;
name = !string.IsNullOrEmpty(e.Result.DisplayName) ? e.Result.DisplayName : e.Result.TestCase.DisplayName;

if (e.Result.Outcome == TestOutcome.Skipped)
{
this.testsSkipped++;
if (!this.verbosityLevel.Equals(Verbosity.Quiet))
{
var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.SkippedTestIndicator,
name);
Output.Warning(false, output);
DisplayFullInformation(e.Result);
}
}
else if (e.Result.Outcome == TestOutcome.Failed)
{
this.testOutcome = TestOutcome.Failed;
this.testsFailed++;
if (!this.verbosityLevel.Equals(Verbosity.Quiet))
{
var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.FailedTestIndicator,
name);
Output.Information(false, ConsoleColor.Red, output);
DisplayFullInformation(e.Result);
}
}
else if (e.Result.Outcome == TestOutcome.Passed)
string testDisplayName = e.Result.DisplayName;
if (string.IsNullOrWhiteSpace(e.Result.DisplayName))
{
if (this.verbosityLevel.Equals(Verbosity.Normal))
{
var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.PassedTestIndicator, name);
Output.Information(false, output);
DisplayFullInformation(e.Result);
}
this.testsPassed++;
testDisplayName = e.Result.TestCase.DisplayName;
}
else

switch (e.Result.Outcome)
{
if (!this.verbosityLevel.Equals(Verbosity.Quiet))
{
var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.NotRunTestIndicator,
name);
Output.Information(false, output);
DisplayFullInformation(e.Result);
}
case TestOutcome.Skipped:
{
testsSkipped++;
if (verbosityLevel == Verbosity.Quiet)
{
break;
}

var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.SkippedTestIndicator, testDisplayName);
Output.Warning(false, output);
if (verbosityLevel == Verbosity.Detailed)
{
DisplayFullInformation(e.Result);
}

break;
}

case TestOutcome.Failed:
{
testsFailed++;
if (verbosityLevel == Verbosity.Quiet)
{
break;
}

var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.FailedTestIndicator, testDisplayName);
Output.Information(false, ConsoleColor.Red, output);
DisplayFullInformation(e.Result);
break;
}

case TestOutcome.Passed:
{
testsPassed++;
if (verbosityLevel == Verbosity.Quiet)
{
break;
}

var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.PassedTestIndicator, testDisplayName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Minimal level the passed test name should not get displayed. Update the test to catch this scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Output.Information(false, output);
if (verbosityLevel == Verbosity.Detailed)
{
DisplayFullInformation(e.Result);
}

break;
}

default:
{
if (verbosityLevel == Verbosity.Quiet)
{
break;
}

var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.NotRunTestIndicator, testDisplayName);
Output.Information(false, output);
if (verbosityLevel == Verbosity.Detailed)
{
DisplayFullInformation(e.Result);
}

break;
}
}
}

Expand Down Expand Up @@ -429,7 +457,7 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
}

// Output a summary.
if (this.testsTotal > 0)
if (testsTotal > 0)
{
string testCountDetails;

Expand All @@ -453,16 +481,16 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
{
Output.Error(false, CommandLineResources.TestRunAborted);
}
else if (this.testOutcome == TestOutcome.Failed && this.testsTotal > 0)
else if (testsFailed > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testsFailed [](start = 21, length = 11)

We should revert this one.
We could have a passing tests and then we some failure occurred.
TestOutcome is set to failed in case some error occurs during the run, it is not necessary that we would have failing test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Will fix this. Didnt see any UT failing though.. will add one.

{
Output.Error(false, CommandLineResources.TestRunFailed);
}
else if(this.testsTotal > 0)
else if (testsTotal > 0)
{
Output.Information(false, ConsoleColor.Green, CommandLineResources.TestRunSuccessful);
}

if (this.testsTotal > 0)
if (testsTotal > 0)
{
if (!e.ElapsedTimeInRunningTests.Equals(TimeSpan.Zero))
{
Expand Down
70 changes: 65 additions & 5 deletions test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,66 @@ public void TestResultHandlerShouldShowStdOutMessagesBannerIfStdOutIsNotEmpty()
this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once());
}

[TestMethod]
public void NormalVerbosityShowNotStdOutMessagesForPassedTests()
{
// Setup
var parameters = new Dictionary<string, string>
{
{ "verbosity", "normal" }
};

this.consoleLogger.Initialize(this.events.Object, parameters);
var testcase = new TestCase("TestName", new Uri("some://uri"), "TestSource");
string message = "Dummy message";
TestResultMessage testResultMessage = new TestResultMessage(TestResultMessage.StandardOutCategory, message);

var testresult = new ObjectModel.TestResult(testcase);
testresult.Outcome = TestOutcome.Passed;
testresult.Messages.Add(testResultMessage);

var eventArgs = new TestRunChangedEventArgs(null, new List<ObjectModel.TestResult> { testresult }, null);

// Raise an event on mock object
this.testRunRequest.Raise(m => m.OnRunStatsChange += null, eventArgs);
this.FlushLoggerMessages();

// Verify
this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Never());
this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Never());
}

[TestMethod]
public void DetailedVerbosityShowStdOutMessagesForPassedTests()
{
// Setup
var parameters = new Dictionary<string, string>
{
{ "verbosity", "detailed" }
};

this.consoleLogger.Initialize(this.events.Object, parameters);
var testcase = new TestCase("TestName", new Uri("some://uri"), "TestSource");
string message = "Dummy message";
TestResultMessage testResultMessage = new TestResultMessage(TestResultMessage.StandardOutCategory, message);

var testresult = new ObjectModel.TestResult(testcase)
{
Outcome = TestOutcome.Passed
};

testresult.Messages.Add(testResultMessage);
var eventArgs = new TestRunChangedEventArgs(null, new List<ObjectModel.TestResult> { testresult }, null);

// Act. Raise an event on mock object
this.testRunRequest.Raise(m => m.OnRunStatsChange += null, eventArgs);
this.FlushLoggerMessages();

// Verify
this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Once());
this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once());
}

[TestMethod]
public void TestResultHandlerShouldNotShowStdOutMessagesBannerIfStdOutIsEmpty()
{
Expand Down Expand Up @@ -334,7 +394,7 @@ public void TestResultHandlerShouldWriteToConsoleShouldShowPassedTestsForNormalV
}

[TestMethod]
public void TestResultHandlerShouldShowStdOutMsgOfPassedTestIfVerbosityIsNormal()
public void TestResultHandlerShouldShowNotStdOutMsgOfPassedTestIfVerbosityIsNormal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestResultHandlerShouldShowNotStdOutMsgOfPassedTestIfVerbosityIsNormal [](start = 20, length = 70)

Nit: ShouldNotShow
please change the name for test following this one as well.

{
var parameters = new Dictionary<string, string>();
parameters.Add("verbosity", "normal");
Expand All @@ -355,8 +415,8 @@ public void TestResultHandlerShouldShowStdOutMsgOfPassedTestIfVerbosityIsNormal(
this.testRunRequest.Raise(m => m.OnRunStatsChange += null, eventArgs);
this.FlushLoggerMessages();

this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Once());
this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once());
this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Never());
this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Never());
}

[TestMethod]
Expand All @@ -381,8 +441,8 @@ public void TestResultHandlerShouldShowDbgTrcMsg()
this.testRunRequest.Raise(m => m.OnRunStatsChange += null, eventArgs);
this.FlushLoggerMessages();

this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.DbgTrcMessagesBanner, OutputLevel.Information), Times.Once());
this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once());
this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.DbgTrcMessagesBanner, OutputLevel.Information), Times.Never());
this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Never());
}


Expand Down