Skip to content

Commit

Permalink
Send message as warning in case of error stream, informational otherw…
Browse files Browse the repository at this point in the history
…ise (#1037) (#1038)

* Send message as warning in case of error stream, informational otherwise (#1037)

* Moved TestOutput unit test to separate region (#1037)

Co-authored-by: Martin Harwig <m.harwig@ellips.com>
  • Loading branch information
mharwig and Martin Harwig committed Dec 5, 2022
1 parent cd91fba commit 82660ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/NUnitTestAdapter/NUnitEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ public void TestOutput(INUnitTestEventTestOutput outputNodeEvent)
outputNodes.Add(outputNodeEvent);
}

recorder.SendMessage(TestMessageLevel.Warning, text);
var testMessageLevel = outputNodeEvent.IsErrorStream
? TestMessageLevel.Warning
: TestMessageLevel.Informational;

recorder.SendMessage(testMessageLevel, text);
}
}
}
20 changes: 20 additions & 0 deletions src/NUnitTestAdapterTests/NUnitEventListenerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public void TestFinished_CallsRecordResultCorrectly()
VerifyTestResult(testLog.Events[1].TestResult);
}


// [TestCase(ResultState.Success, TestOutcome.Passed, null)]
// [TestCase(ResultState.Failure, TestOutcome.Failed, "My failure message")]
// [TestCase(ResultState.Error, TestOutcome.Failed, "Error!")]
Expand Down Expand Up @@ -166,6 +167,25 @@ public void TestFinished_CallsRecordResultCorrectly()

#endregion

#region TestOutput Tests

[TestCase(NUnitTestEventTestOutput.Streams.Error, TestMessageLevel.Warning, TestName = "TestOutput with 'Error' stream is send as message level Warning")]
[TestCase(NUnitTestEventTestOutput.Streams.Progress, TestMessageLevel.Informational, TestName = "TestOutput with 'Progress' stream is send as message level Informational")]
[TestCase(NUnitTestEventTestOutput.Streams.NoIdea, TestMessageLevel.Informational, TestName = "TestOutput with 'NoIdea' stream is send as message level Informational")]
public void TestOutput_SendsMessageWithCorrectMessageLevel(NUnitTestEventTestOutput.Streams streamType, TestMessageLevel expectedTestMessageLevel)
{
var outPutXml = @$"<test-output stream='{streamType}' testid='0-1001' testname='Something.TestClass.SomeTest'><![CDATA[SomeData]]></test-output>";
var testOutput = new NUnitTestEventTestOutput(XmlHelper.CreateXmlNode(outPutXml));

listener.TestOutput(testOutput);
Assume.That(testLog.Events.Count, Is.EqualTo(1));
Assume.That(testLog.Events[0].EventType, Is.EqualTo(FakeFrameworkHandle.EventType.SendMessage));

Assert.That(testLog.Events[0].Message.Level, Is.EqualTo(expectedTestMessageLevel));
}

#endregion

#region Listener Lifetime Tests
#if NET35
[Test]
Expand Down

0 comments on commit 82660ca

Please sign in to comment.