Skip to content

Commit

Permalink
feat: Include inconclusive tests count in test report.
Browse files Browse the repository at this point in the history
dotnet test reports both both inconclusive and explicittest annotated
tests as TestOutcome.None. Report both of these results as inconclusive
in the xml report. This is the entirely correct if user has both kinds of
tests, however it is slightly better than not including inconclusive tests
at all.

Fixes #31.
  • Loading branch information
codito committed Sep 8, 2018
1 parent 1ecf3d0 commit 913621a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
42 changes: 25 additions & 17 deletions src/NUnit.Xml.TestLogger/NUnitXmlTestLogger.cs
Expand Up @@ -71,7 +71,7 @@ public override bool Equals(object obj)
{
if (obj is TestResultInfo)
{
TestResultInfo objectToCompare = (TestResultInfo) obj;
TestResultInfo objectToCompare = (TestResultInfo)obj;
if (string.Compare(ErrorMessage, objectToCompare.ErrorMessage) == 0
&& string.Compare(ErrorStackTrace, objectToCompare.ErrorStackTrace) == 0)
{
Expand Down Expand Up @@ -200,27 +200,28 @@ internal void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
private XElement CreateAssembliesElement(List<TestResultInfo> results)
{
var testSuites = from result in results
group result by result.AssemblyPath
into resultsByAssembly
orderby resultsByAssembly.Key
select CreateTestSuiteElement(resultsByAssembly);
group result by result.AssemblyPath
into resultsByAssembly
orderby resultsByAssembly.Key
select CreateTestSuiteElement(resultsByAssembly);

var element = new XElement("test-run", testSuites);

element.SetAttributeValue("id", 2);

element.SetAttributeValue("duration", results.Sum(x => x.Time.TotalSeconds));

var total = testSuites.Sum(x => (int) x.Attribute("total"));
var total = testSuites.Sum(x => (int)x.Attribute("total"));

// TODO test case count is actually count before filtering
element.SetAttributeValue("testcasecount", total);
element.SetAttributeValue("total", total);
element.SetAttributeValue("passed", testSuites.Sum(x => (int) x.Attribute("passed")));
element.SetAttributeValue("passed", testSuites.Sum(x => (int)x.Attribute("passed")));

var failed = testSuites.Sum(x => (int) x.Attribute("failed"));
var failed = testSuites.Sum(x => (int)x.Attribute("failed"));
element.SetAttributeValue("failed", failed);
element.SetAttributeValue("skipped", testSuites.Sum(x => (int) x.Attribute("skipped")));
element.SetAttributeValue("inconclusive", testSuites.Sum(x => (int)x.Attribute("inconclusive")));
element.SetAttributeValue("skipped", testSuites.Sum(x => (int)x.Attribute("skipped")));

var resultString = failed > 0 ? ResultStatusFailed : ResultStatusPassed;
element.SetAttributeValue("result", resultString);
Expand All @@ -237,15 +238,16 @@ private XElement CreateTestSuiteElement(IGrouping<string, TestResultInfo> result
var assemblyPath = resultsByAssembly.Key;

var collections = from resultsInAssembly in resultsByAssembly
group resultsInAssembly by resultsInAssembly.Type
into resultsByType
orderby resultsByType.Key
select CreateTestSuite(resultsByType);
group resultsInAssembly by resultsInAssembly.Type
into resultsByType
orderby resultsByType.Key
select CreateTestSuite(resultsByType);

int total = 0;
int passed = 0;
int failed = 0;
int skipped = 0;
int inconclusive = 0;
int errors = 0;
var time = TimeSpan.Zero;

Expand All @@ -260,6 +262,7 @@ orderby resultsByType.Key
total += collection.total;
passed += collection.passed;
failed += collection.failed;
inconclusive += collection.inconclusive;
skipped += collection.skipped;
errors += collection.error;
time += collection.time;
Expand All @@ -273,6 +276,7 @@ orderby resultsByType.Key
element.SetAttributeValue("total", total);
element.SetAttributeValue("passed", passed);
element.SetAttributeValue("failed", failed);
element.SetAttributeValue("inconclusive", inconclusive);
element.SetAttributeValue("skipped", skipped);
element.SetAttributeValue("duration", time.TotalSeconds);
element.SetAttributeValue("errors", errors);
Expand Down Expand Up @@ -313,7 +317,7 @@ private static XElement CreateFailureElement(string exceptionType, string messag
return failureElement;
}

private static (XElement element, int total, int passed, int failed, int skipped, int error, TimeSpan time) CreateTestSuite(IGrouping<string, TestResultInfo> resultsByType
private static (XElement element, int total, int passed, int failed, int inconclusive, int skipped, int error, TimeSpan time) CreateTestSuite(IGrouping<string, TestResultInfo> resultsByType
)
{
var element = new XElement("test-suite");
Expand All @@ -322,6 +326,7 @@ private static XElement CreateFailureElement(string exceptionType, string messag
int passed = 0;
int failed = 0;
int skipped = 0;
int inconclusive = 0;
int error = 0;
var time = TimeSpan.Zero;

Expand All @@ -338,9 +343,11 @@ private static XElement CreateFailureElement(string exceptionType, string messag
break;

case TestOutcome.Skipped:
case TestOutcome.None:
skipped++;
break;
case TestOutcome.None:
inconclusive++;
break;
}

total++;
Expand All @@ -362,14 +369,15 @@ private static XElement CreateFailureElement(string exceptionType, string messag
element.SetAttributeValue("total", total);
element.SetAttributeValue("passed", passed);
element.SetAttributeValue("failed", failed);
element.SetAttributeValue("inconclusive", inconclusive);
element.SetAttributeValue("skipped", skipped);

var resultString = failed > 0 ? ResultStatusFailed : ResultStatusPassed;
element.SetAttributeValue("result", resultString);
element.SetAttributeValue("result", resultString);
element.SetAttributeValue("duration", time.TotalSeconds);

return (element, total, passed, failed, skipped, error, time);
return (element, total, passed, failed, inconclusive, skipped, error, time);
}

private static XElement CreateTestElement(TestResultInfo result)
Expand Down Expand Up @@ -488,7 +496,7 @@ private static string RemoveInvalidXmlChar(string str)
private static string ReplaceInvalidCharacterWithUniCodeEscapeSequence(Match match)
{
char x = match.Value[0];
return string.Format(@"\u{0:x4}", (ushort) x);
return string.Format(@"\u{0:x4}", (ushort)x);
}
}
}
Expand Up @@ -21,7 +21,7 @@
</PropertyGroup>
<Target Name="TestTarget" AfterTargets="Build">
<Message Importance="High" Text="... Building test assets" />
<RemoveDir Directories="$(NuGetPackageRoot)/xunitxml.testlogger" />
<RemoveDir Directories="$(NuGetPackageRoot)/nunitxml.testlogger" />
<Exec ContinueOnError="False" Command="dotnet build -c $(Configuration) -p:RestoreConfigFile=$(TestRestoreConfig) -p:RestoreIgnoreFailedSources=true -p:RestoreNoCache=true $(TestCoreProject)"/>
<Exec ContinueOnError="False" Command="dotnet build -c $(Configuration) -p:RestoreConfigFile=$(TestRestoreConfig) -p:RestoreIgnoreFailedSources=true -p:RestoreNoCache=true $(TestFullProject)"/>
<Message Importance="High" Text="... Completed" />
Expand Down
Expand Up @@ -40,7 +40,8 @@ public void TestResultFileShouldContainTestRunInformation()
Assert.AreEqual("21", node.Attribute(XName.Get("testcasecount")).Value);
Assert.AreEqual("7", node.Attribute(XName.Get("passed")).Value);
Assert.AreEqual("7", node.Attribute(XName.Get("failed")).Value);
Assert.AreEqual("7", node.Attribute(XName.Get("skipped")).Value);
Assert.AreEqual("4", node.Attribute(XName.Get("inconclusive")).Value);
Assert.AreEqual("3", node.Attribute(XName.Get("skipped")).Value);
Assert.AreEqual("Failed", node.Attribute(XName.Get("result")).Value);

// Start time and End time should be valid dates
Expand All @@ -57,7 +58,8 @@ public void TestResultFileShouldContainAssemblyTestSuite()
Assert.AreEqual("21", node.Attribute(XName.Get("total")).Value);
Assert.AreEqual("7", node.Attribute(XName.Get("passed")).Value);
Assert.AreEqual("7", node.Attribute(XName.Get("failed")).Value);
Assert.AreEqual("7", node.Attribute(XName.Get("skipped")).Value);
Assert.AreEqual("4", node.Attribute(XName.Get("inconclusive")).Value);
Assert.AreEqual("3", node.Attribute(XName.Get("skipped")).Value);
Assert.AreEqual("Failed", node.Attribute(XName.Get("result")).Value);
Assert.AreEqual("NUnit.Xml.TestLogger.NetCore.Tests.dll", node.Attribute(XName.Get("name")).Value);
Assert.AreEqual(DotnetTestFixture.TestAssembly, node.Attribute(XName.Get("fullname")).Value);
Expand Down
Expand Up @@ -8,8 +8,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="NUnit" Version="3.8.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="NunitXml.TestLogger" Version="$(PackageVersion)" />
</ItemGroup>

Expand Down

0 comments on commit 913621a

Please sign in to comment.