From ad5496682ce04e9959911b19e427771699b053da Mon Sep 17 00:00:00 2001 From: Arun Mahapatra Date: Wed, 3 Feb 2021 19:31:38 +0530 Subject: [PATCH] fix: use traits from TestCase instead of TestResult. Fixes #32. (#33) --- CHANGELOG.md | 4 ++++ src/Xunit.Xml.TestLogger/XunitXmlSerializer.cs | 4 ++-- .../TestResultsXmlTests.cs | 7 +++++-- .../assets/Xunit.Xml.TestLogger.NetCore.Tests/UnitTest1.cs | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a99883..7141efb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased (v3.1.x) +- Remove unused code from refactoring. See #31 +- Use `TestResultInfo.TestCase.Traits` instead of `TestResultInfo.Traits`. See + #32 + ## v3.0.56 - 2021/01/31 - Refactor to support [core testlogger][] diff --git a/src/Xunit.Xml.TestLogger/XunitXmlSerializer.cs b/src/Xunit.Xml.TestLogger/XunitXmlSerializer.cs index 447f36e..3f74fb2 100644 --- a/src/Xunit.Xml.TestLogger/XunitXmlSerializer.cs +++ b/src/Xunit.Xml.TestLogger/XunitXmlSerializer.cs @@ -288,9 +288,9 @@ private static XElement CreateTestElement(TestResultInfo result) new XElement("stack-trace", result.ErrorStackTrace.ReplaceInvalidXmlChar()))); } - if (result.Traits != null) + if (result.TestCase.Traits != null) { - var traits = from trait in result.Traits + var traits = from trait in result.TestCase.Traits select new XElement("trait", new XAttribute("name", trait.Name), new XAttribute("value", trait.Value)); element.Add(new XElement("traits", traits)); } diff --git a/test/Xunit.Xml.TestLogger.AcceptanceTests/TestResultsXmlTests.cs b/test/Xunit.Xml.TestLogger.AcceptanceTests/TestResultsXmlTests.cs index 37473b9..139b99d 100644 --- a/test/Xunit.Xml.TestLogger.AcceptanceTests/TestResultsXmlTests.cs +++ b/test/Xunit.Xml.TestLogger.AcceptanceTests/TestResultsXmlTests.cs @@ -288,8 +288,11 @@ public void TestElementShouldHaveTraits() { XmlNode failedTestXmlNode = this.GetATestXmlNode(); - // TODO add traits to tests and update the assert. - Assert.Equal(string.Empty, failedTestXmlNode.SelectSingleNode("traits").InnerText); + var traits = failedTestXmlNode.SelectSingleNode("traits")?.ChildNodes; + Assert.NotNull(traits); + Assert.Equal(1, traits.Count); + Assert.Equal("Category", traits[0].Attributes["name"].Value); + Assert.Equal("DummyCategory", traits[0].Attributes["value"].Value); } [Fact] diff --git a/test/assets/Xunit.Xml.TestLogger.NetCore.Tests/UnitTest1.cs b/test/assets/Xunit.Xml.TestLogger.NetCore.Tests/UnitTest1.cs index 67dcaa3..378d1bc 100644 --- a/test/assets/Xunit.Xml.TestLogger.NetCore.Tests/UnitTest1.cs +++ b/test/assets/Xunit.Xml.TestLogger.NetCore.Tests/UnitTest1.cs @@ -11,6 +11,7 @@ public void PassTest11() } [Fact] + [Trait("Category", "DummyCategory")] public void FailTest11() { Assert.False(true);