Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/NUnitTestAdapter/NUnitEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ public void SuiteFinished(INUnitTestEventSuiteFinished resultNode)
if (!OutputPolicy.ShowsLiveOutput(output.IsErrorStream))
Recorder.SendMessage(TestMessageLevel.Warning, output.Content.TrimEnd());
}

// Standard output (Console.Out, TestContext.Out) is never sent live, NUnit keeps it in the suite result
if (OutputPolicy.CollectsOutput(isErrorStream: false) && !resultNode.Output.IsNullOrWhiteSpace())
Recorder.SendMessage(TestMessageLevel.Warning, resultNode.Output.TrimEnd());
}

private static readonly string Nl = Environment.NewLine;
Expand Down
30 changes: 30 additions & 0 deletions src/NUnitTestAdapterTests/NUnitEventListenerOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,36 @@ public void ThatAgentModeSendsBufferedOutputOfFailedSuite()
recorder.Received().SendMessage(TestMessageLevel.Warning, "Setup diagnostics");
}

/// <summary>
/// Standard output written in a failing OneTimeSetUp is only in the suite result, not in a test-output event.
/// </summary>
[TestCase("All", true)]
[TestCase("Failed", true)]
[TestCase("None", false)]
public void ThatStandardOutputOfFailedSuiteIsSent(string showStdout, bool expectSent)
{
UseRealSettings($"<ShowStdout>{showStdout}</ShowStdout>");
var sut = new NUnitEventListener(converter, executor);

sut.OnTestEvent("<test-suite type='TestFixture' id='0-1000' name='UnitTests' fullname='UnitTests' result='Failed' site='SetUp'><failure><message><![CDATA[Boom]]></message></failure><output><![CDATA[Setup stdout\n]]></output></test-suite>");

if (expectSent)
recorder.Received().SendMessage(TestMessageLevel.Warning, "Setup stdout");
else
recorder.DidNotReceive().SendMessage(Arg.Any<TestMessageLevel>(), "Setup stdout");
}

[Test]
public void ThatStandardOutputOfPassingSuiteIsNotSent()
{
UseRealSettings("<ShowStdout>All</ShowStdout>");
var sut = new NUnitEventListener(converter, executor);

sut.OnTestEvent("<test-suite type='TestFixture' id='0-1000' name='UnitTests' fullname='UnitTests' result='Passed'><output><![CDATA[Setup stdout\n]]></output></test-suite>");

recorder.DidNotReceive().SendMessage(Arg.Any<TestMessageLevel>(), Arg.Any<string>());
}

private void ConverterReturns(TestOutcome outcome, string consoleOutput)
{
var testCase = new TestCase("UnitTests.Test1", new Uri(NUnit3TestExecutor.ExecutorUri), "UnitTests.dll");
Expand Down