Skip to content

Commit

Permalink
fix: use traits from TestCase instead of TestResult. Fixes #32. (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
codito authored Feb 3, 2021
1 parent 3e5964e commit ad54966
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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][]
Expand Down
4 changes: 2 additions & 2 deletions src/Xunit.Xml.TestLogger/XunitXmlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public void PassTest11()
}

[Fact]
[Trait("Category", "DummyCategory")]
public void FailTest11()
{
Assert.False(true);
Expand Down

0 comments on commit ad54966

Please sign in to comment.