From 82660ca8447e366ea0ee2e2211ac95db141ab9d1 Mon Sep 17 00:00:00 2001 From: mharwig <119603920+mharwig@users.noreply.github.com> Date: Mon, 5 Dec 2022 16:31:24 +0100 Subject: [PATCH] Send message as warning in case of error stream, informational otherwise (#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 --- src/NUnitTestAdapter/NUnitEventListener.cs | 6 +++++- .../NUnitEventListenerTests.cs | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/NUnitTestAdapter/NUnitEventListener.cs b/src/NUnitTestAdapter/NUnitEventListener.cs index f483875c..1d66ef2c 100644 --- a/src/NUnitTestAdapter/NUnitEventListener.cs +++ b/src/NUnitTestAdapter/NUnitEventListener.cs @@ -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); } } } diff --git a/src/NUnitTestAdapterTests/NUnitEventListenerTests.cs b/src/NUnitTestAdapterTests/NUnitEventListenerTests.cs index 12f3c72c..2a4e531a 100644 --- a/src/NUnitTestAdapterTests/NUnitEventListenerTests.cs +++ b/src/NUnitTestAdapterTests/NUnitEventListenerTests.cs @@ -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!")] @@ -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 = @$""; + 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]