Skip to content

Commit ea779b1

Browse files
authored
Show all type of messages( sdtOut, stdErr etc) for passed tests (#809)
* Show all type of messages likesdtOut, stdErr etc for passed tests * Address PR comment
1 parent 16a055b commit ea779b1

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

src/vstest.console/Internal/ConsoleLogger.cs

+15
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ private static void DisplayFullInformation(TestResult result)
263263
}
264264
}
265265

266+
var DbgTrcMessagesCollection = GetTestMessages(result.Messages, TestResultMessage.DebugTraceCategory);
267+
if (DbgTrcMessagesCollection.Count > 0)
268+
{
269+
addAdditionalNewLine = false;
270+
var dbgTrcMessages = GetFormattedOutput(DbgTrcMessagesCollection);
271+
272+
if (!string.IsNullOrEmpty(dbgTrcMessages))
273+
{
274+
Output.Information(CommandLineResources.DbgTrcMessagesBanner);
275+
Output.Information(dbgTrcMessages);
276+
}
277+
}
278+
266279
var addnlInfoMessagesCollection = GetTestMessages(result.Messages, TestResultMessage.AdditionalInfoCategory);
267280
if (addnlInfoMessagesCollection.Count > 0)
268281
{
@@ -275,6 +288,7 @@ private static void DisplayFullInformation(TestResult result)
275288
Output.Information(addnlInfoMessages);
276289
}
277290
}
291+
278292
if (addAdditionalNewLine)
279293
{
280294
Output.WriteLine(String.Empty, OutputLevel.Information);
@@ -354,6 +368,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e)
354368
{
355369
var output = string.Format(CultureInfo.CurrentCulture, CommandLineResources.PassedTestIndicator, name);
356370
Output.Information(output);
371+
DisplayFullInformation(e.Result);
357372
}
358373
this.testsPassed++;
359374
}

src/vstest.console/Resources/Resources.Designer.cs

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vstest.console/Resources/Resources.resx

+3
Original file line numberDiff line numberDiff line change
@@ -652,4 +652,7 @@
652652
<data name="DataCollectorFriendlyNameInvalid" xml:space="preserve">
653653
<value>The Data Collector friendly name '{0}' is not valid. The Data Collector will be ignored.</value>
654654
</data>
655+
<data name="DbgTrcMessagesBanner" xml:space="preserve">
656+
<value>Debug Traces Messages:</value>
657+
</data>
655658
</root>

test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs

+53
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,59 @@ public void TestResultHandlerShouldWriteToConsoleShouldShowPassedTestsForNormalV
314314
this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.NotRunTestIndicator, "TestName"), OutputLevel.Information), Times.Exactly(2));
315315
}
316316

317+
[TestMethod]
318+
public void TestResultHandlerShouldShowStdOutMsgOfPassedTestIfVerbosityIsNormal()
319+
{
320+
var parameters = new Dictionary<string, string>();
321+
parameters.Add("verbosity", "normal");
322+
this.consoleLogger.Initialize(this.events.Object, parameters);
323+
324+
var testcase = new TestCase("TestName", new Uri("some://uri"), "TestSource");
325+
326+
string message = "Dummy message";
327+
TestResultMessage testResultMessage = new TestResultMessage(TestResultMessage.StandardOutCategory, message);
328+
329+
var testresult = new ObjectModel.TestResult(testcase);
330+
testresult.Outcome = TestOutcome.Passed;
331+
testresult.Messages.Add(testResultMessage);
332+
333+
var eventArgs = new TestRunChangedEventArgs(null, new List<ObjectModel.TestResult> { testresult }, null);
334+
335+
// Raise an event on mock object
336+
this.testRunRequest.Raise(m => m.OnRunStatsChange += null, eventArgs);
337+
this.FlushLoggerMessages();
338+
339+
this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Once());
340+
this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once());
341+
}
342+
343+
[TestMethod]
344+
public void TestResultHandlerShouldShowDbgTrcMsg()
345+
{
346+
var parameters = new Dictionary<string, string>();
347+
parameters.Add("verbosity", "normal");
348+
this.consoleLogger.Initialize(this.events.Object, parameters);
349+
350+
var testcase = new TestCase("TestName", new Uri("some://uri"), "TestSource");
351+
352+
string message = "Dummy message";
353+
TestResultMessage testResultMessage = new TestResultMessage(TestResultMessage.DebugTraceCategory, message);
354+
355+
var testresult = new ObjectModel.TestResult(testcase);
356+
testresult.Outcome = TestOutcome.Passed;
357+
testresult.Messages.Add(testResultMessage);
358+
359+
var eventArgs = new TestRunChangedEventArgs(null, new List<ObjectModel.TestResult> { testresult }, null);
360+
361+
// Raise an event on mock object
362+
this.testRunRequest.Raise(m => m.OnRunStatsChange += null, eventArgs);
363+
this.FlushLoggerMessages();
364+
365+
this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.DbgTrcMessagesBanner, OutputLevel.Information), Times.Once());
366+
this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once());
367+
}
368+
369+
317370
[TestMethod]
318371
public void TestResultHandlerShouldWriteToConsoleButSkipPassedTestsForMinimalVerbosity()
319372
{

0 commit comments

Comments
 (0)