-
Notifications
You must be signed in to change notification settings - Fork 325
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
Changes from 5 commits
43d9bb2
1174f6b
14d55fd
2496626
c99139c
039d89f
b7ec379
4416801
67b5fb4
98ede93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,8 @@ internal enum Verbosity | |
{ | ||
Quiet, | ||
Minimal, | ||
Normal | ||
Normal, | ||
Detailed | ||
} | ||
|
||
#region Fields | ||
|
@@ -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; | ||
|
@@ -142,9 +142,9 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory) | |
} | ||
|
||
// Register for the events. | ||
events.TestRunMessage += this.TestMessageHandler; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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 | ||
|
||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -429,7 +457,7 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) | |
} | ||
|
||
// Output a summary. | ||
if (this.testsTotal > 0) | ||
if (testsTotal > 0) | ||
{ | ||
string testCountDetails; | ||
|
||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We should revert this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
{ | ||
|
@@ -334,7 +394,7 @@ public void TestResultHandlerShouldWriteToConsoleShouldShowPassedTestsForNormalV | |
} | ||
|
||
[TestMethod] | ||
public void TestResultHandlerShouldShowStdOutMsgOfPassedTestIfVerbosityIsNormal() | ||
public void TestResultHandlerShouldShowNotStdOutMsgOfPassedTestIfVerbosityIsNormal() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Nit: ShouldNotShow |
||
{ | ||
var parameters = new Dictionary<string, string>(); | ||
parameters.Add("verbosity", "normal"); | ||
|
@@ -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] | ||
|
@@ -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()); | ||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
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.