diff --git a/src/NUnitTestAdapter/TestConverter.cs b/src/NUnitTestAdapter/TestConverter.cs index d5ae9301..0f101cd6 100644 --- a/src/NUnitTestAdapter/TestConverter.cs +++ b/src/NUnitTestAdapter/TestConverter.cs @@ -101,26 +101,38 @@ public TestCase GetCachedTestCase(string id) } private static readonly string NL = Environment.NewLine; - + public TestResultSet GetVSTestResults(XmlNode resultNode, ICollection outputNodes) { var results = new List(); - XmlNodeList assertions = resultNode.SelectNodes("assertions/assertion"); + var testcaseResult = GetBasicResult(resultNode, outputNodes); - foreach (XmlNode assertion in assertions) + + if (testcaseResult != null) { - var oneResult = GetBasicResult(resultNode, outputNodes); // we need a new copy, this is currently the simplest way - if (oneResult != null) + if (testcaseResult.Outcome == TestOutcome.Failed || testcaseResult.Outcome == TestOutcome.NotFound) { - oneResult.Outcome = GetAssertionOutcome(assertion); - oneResult.ErrorMessage = assertion.SelectSingleNode("message")?.InnerText; - oneResult.ErrorStackTrace = assertion.SelectSingleNode("stack-trace")?.InnerText; - results.Add(oneResult); + testcaseResult.ErrorMessage = resultNode.SelectSingleNode("failure/message")?.InnerText; + testcaseResult.ErrorStackTrace = resultNode.SelectSingleNode("failure/stack-trace")?.InnerText; + + // find stacktrace in assertion nodes if not defined (seems .netcore2.0 doesn't provide stack-trace for Assert.Fail("abc")) + if (testcaseResult.ErrorStackTrace == null) + { + string stackTrace = string.Empty; + foreach (XmlNode assertionStacktraceNode in resultNode.SelectNodes("assertions/assertion/stack-trace")) + { + stackTrace += assertionStacktraceNode.InnerText; + } + testcaseResult.ErrorStackTrace = stackTrace; + } + } + else if (testcaseResult.Outcome == TestOutcome.Skipped || testcaseResult.Outcome == TestOutcome.None) + { + testcaseResult.ErrorMessage = resultNode.SelectSingleNode("reason/message")?.InnerText; } - } - if (testcaseResult!=null && testcaseResult.Outcome == TestOutcome.Failed && results.Any() && results.All(o => o.Outcome != TestOutcome.Failed)) - results.First().Outcome = TestOutcome.Failed; + results.Add(testcaseResult); + } if (results.Count == 0) { @@ -129,7 +141,7 @@ public TestResultSet GetVSTestResults(XmlNode resultNode, ICollection o results.Add(result); } - return new TestResultSet {TestCaseResult = testcaseResult, TestResults = results}; + return new TestResultSet { TestCaseResult = testcaseResult, TestResults = results }; } public struct TestResultSet @@ -169,7 +181,7 @@ private TestCase MakeTestCaseFromXmlNode(XmlNode testNode) } } - testCase.AddTraitsFromTestNode(testNode, TraitsCache,_logger,adapterSettings); + testCase.AddTraitsFromTestNode(testNode, TraitsCache, _logger, adapterSettings); return testCase; } @@ -271,7 +283,7 @@ private AttachmentSet ParseAttachments(XmlNode resultNode) var path = attachment.SelectSingleNode("filePath")?.InnerText ?? string.Empty; var description = attachment.SelectSingleNode("description")?.InnerText; - if ( !(string.IsNullOrEmpty(path) || path.StartsWith(fileUriScheme, StringComparison.OrdinalIgnoreCase))) + if (!(string.IsNullOrEmpty(path) || path.StartsWith(fileUriScheme, StringComparison.OrdinalIgnoreCase))) { path = fileUriScheme + path; } diff --git a/src/NUnitTestAdapterTests/NUnitEventListenerTests.cs b/src/NUnitTestAdapterTests/NUnitEventListenerTests.cs index 309ec5da..53dba55b 100644 --- a/src/NUnitTestAdapterTests/NUnitEventListenerTests.cs +++ b/src/NUnitTestAdapterTests/NUnitEventListenerTests.cs @@ -194,7 +194,7 @@ private void VerifyTestResult(VSTestResult ourResult) Assert.AreEqual(Environment.MachineName, ourResult.ComputerName); Assert.AreEqual(TestOutcome.Passed, ourResult.Outcome); - Assert.AreEqual("It passed!", ourResult.ErrorMessage); + Assert.AreEqual(null, ourResult.ErrorMessage); Assert.AreEqual(TimeSpan.FromSeconds(1.234), ourResult.Duration); } diff --git a/src/NUnitTestAdapterTests/TestConverterTests.cs b/src/NUnitTestAdapterTests/TestConverterTests.cs index 425e4f47..ac1ac34f 100644 --- a/src/NUnitTestAdapterTests/TestConverterTests.cs +++ b/src/NUnitTestAdapterTests/TestConverterTests.cs @@ -146,7 +146,7 @@ public void CanMakeTestResultFromNUnitTestResult() CheckTestCase(testCase); Assert.That(testResult.Outcome, Is.EqualTo(TestOutcome.Passed)); - Assert.That(testResult.ErrorMessage, Is.EqualTo("It passed!")); + Assert.That(testResult.ErrorMessage, Is.EqualTo(null)); Assert.That(testResult.Duration, Is.EqualTo(TimeSpan.FromSeconds(1.234))); } diff --git a/src/NUnitTestAdapterTests/TestExecutionTests.cs b/src/NUnitTestAdapterTests/TestExecutionTests.cs index 175f8bfc..4e70a9da 100644 --- a/src/NUnitTestAdapterTests/TestExecutionTests.cs +++ b/src/NUnitTestAdapterTests/TestExecutionTests.cs @@ -157,7 +157,7 @@ public int TestOutcomeTotalsAreCorrect(TestOutcome outcome) .Count(e => e.EventType == FakeFrameworkHandle.EventType.RecordResult && e.TestResult.Outcome == outcome); } - [TestCase("MockTest3", TestOutcome.Passed, "Succeeded!", false)] + [TestCase("MockTest3", TestOutcome.Passed, null, false)] [TestCase("FailingTest", TestOutcome.Failed, "Intentional failure", true)] [TestCase("TestWithException", TestOutcome.Failed, "System.Exception : Intentional Exception", true)] // NOTE: Should Inconclusive be reported as TestOutcome.None? @@ -174,7 +174,7 @@ public void TestResultIsReportedCorrectly(string name, TestOutcome outcome, stri Assert.That(testResult.Outcome, Is.EqualTo(outcome)); Assert.That(testResult.ErrorMessage, Is.EqualTo(message)); if (hasStackTrace) - Assert.NotNull(testResult.ErrorStackTrace); + Assert.NotNull(testResult.ErrorStackTrace, "Unable to find error stacktrace"); } [Test] @@ -202,30 +202,30 @@ public void NativeAssemblyProducesWarning() var fakeFramework = new FakeFrameworkHandle(); // Find the native exaple dll. - var path = Path.Combine( TestContext.CurrentContext.TestDirectory, "NativeTests.dll" ); - Assert.That( File.Exists( path ) ); + var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "NativeTests.dll"); + Assert.That(File.Exists(path)); // Try to execute tests from the dll. TestAdapterUtils.CreateExecutor().RunTests( new[] { path }, context, - fakeFramework ); + fakeFramework); // Gather results. var testResults = fakeFramework.Events - .Where( e => e.EventType == FakeFrameworkHandle.EventType.RecordResult ) - .Select( e => e.TestResult ) + .Where(e => e.EventType == FakeFrameworkHandle.EventType.RecordResult) + .Select(e => e.TestResult) .ToList(); // No tests found. - Assert.That( testResults.Count, Is.EqualTo( 0 ) ); + Assert.That(testResults.Count, Is.EqualTo(0)); // A warning about unsupported assebly format provided. var messages = fakeFramework.Events - .Where( e=> e.EventType == FakeFrameworkHandle.EventType.SendMessage && - e.Message.Level == Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Warning ) - .Select( o => o.Message.Text ); - Assert.That( messages, Has.Some.Contains( "Assembly not supported" ) ); + .Where(e => e.EventType == FakeFrameworkHandle.EventType.SendMessage && + e.Message.Level == Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Warning) + .Select(o => o.Message.Text); + Assert.That(messages, Has.Some.Contains("Assembly not supported")); } #endif @@ -250,8 +250,6 @@ private TestResult GetTestResult(string displayName) .Select(e => e.TestResult) .FirstOrDefault(); } - - }