Skip to content

Commit

Permalink
TrxTestResultXmlParser can read more result types (#76)
Browse files Browse the repository at this point in the history
* trx parser reads Results.TestResultAggregation

* Tests with Results.TestResultAggregation

* Handle more result-types

* Moved string-literals to Strings.resx
  • Loading branch information
gfoidl authored Jul 16, 2020
1 parent bda5211 commit c5eb208
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 6,342 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Xml.Linq;
using trx2junit.Models;
using System.Collections.Generic;
using System.Linq;
using trx2junit.Resources;

namespace trx2junit
{
Expand Down Expand Up @@ -35,7 +36,7 @@ public void Parse()
}
else
{
throw new Exception("Given xml file is not a valid junit file");
throw new Exception(Strings.Xml_not_valid_junit);
}
}
//---------------------------------------------------------------------
Expand All @@ -60,7 +61,7 @@ private static JUnitTestSuite ParseTestSuite(XElement xTestSuite)
}
else
{
throw new Exception("Given xml file is not a valid junit file, attribute 'tests' is missing on testsuite-element");
throw new Exception(Strings.Xml_not_valid_junit_missing_tests);
}

XElement? xStdErr = xTestSuite.Element("system-err");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Linq;
using trx2junit.Models;
using trx2junit.Resources;

namespace trx2junit
{
Expand All @@ -27,7 +28,7 @@ public void Convert()

foreach (var testSuite in testSuites)
{
if (testSuite.Key is null) throw new InvalidOperationException("TestSuite.Key is null");
if (testSuite.Key is null) throw new InvalidOperationException(Strings.TestSuite_key_is_null);

this.AddTestSuite(testSuite.Key, testSuite);
}
Expand Down
29 changes: 27 additions & 2 deletions source/trx2junit/Internal/trx2junit/TrxTestResultXmlParser.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Xml.Linq;
using trx2junit.Models;
using trx2junit.Resources;

namespace trx2junit
{
Expand Down Expand Up @@ -86,7 +88,7 @@ private void ReadUnitTestResults()

if (xResults == null) return;

foreach (XElement xResult in xResults.Elements(s_XN + "UnitTestResult"))
foreach (XElement xResult in GetResultItems(xResults))
{
XElement? xInnerResults = xResult.Element(s_XN + "InnerResults");
if (xInnerResults == null)
Expand Down Expand Up @@ -118,6 +120,29 @@ private void ReadUnitTestResults()
}
}
//---------------------------------------------------------------------
private static readonly string[] s_resultTypes =
{
"UnitTestResult",
"TestResultAggregation",
"GenericTestResult",
"TestResult",
"ManualTestResult"
};
//---------------------------------------------------------------------
private static IEnumerable<XElement> GetResultItems(XElement xResults)
{
foreach (string resultType in s_resultTypes)
{
IEnumerable<XElement> xResultItems = xResults.Elements(s_XN + resultType);
if (xResultItems.Any())
{
return xResultItems;
}
}

throw new Exception(Strings.Trx_not_supported_result_type);
}
//---------------------------------------------------------------------
private static TrxUnitTestResult ParseUnitTestResults(XElement xResult)
{
var unitTestResult = new TrxUnitTestResult
Expand Down
54 changes: 45 additions & 9 deletions source/trx2junit/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions source/trx2junit/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,16 @@
<data name="Args_Output_no_Value" xml:space="preserve">
<value>--output specified, but no value is given. An output-directory needs to specified in this case.</value>
</data>
<data name="TestSuite_key_is_null" xml:space="preserve">
<value>TestSuite.Key is null</value>
</data>
<data name="Trx_not_supported_result_type" xml:space="preserve">
<value>No supported resulttype found in &lt;Results&gt;</value>
</data>
<data name="Xml_not_valid_junit" xml:space="preserve">
<value>Given xml file is not a valid junit file</value>
</data>
<data name="Xml_not_valid_junit_missing_tests" xml:space="preserve">
<value>Given xml file is not a valid junit file, attribute 'tests' is missing on testsuite-element</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Integration
[TestCase("./data/trx/xunit-datadriven.trx" , 3, 1)]
[TestCase("./data/trx/xunit-ignore.trx" , 4, 1)]
[TestCase("./data/trx/xunit-memberdata.trx" , 5, 2)]
[TestCase("./data/trx/jsingh-qualitrol.trx" , 0, 0)]
[TestCase("./data/trx/nunit-testresultaggregation.trx", 3, 1)]
public void File_given___correct_counts(string trxFile, int expectedTestCount, int expectedFailureCount)
{
XElement trx = XElement.Load(trxFile);
Expand Down
52 changes: 26 additions & 26 deletions tests/trx2junit.Tests/Internal/TrxTestResultXmlParserTests/Parse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml.Linq;
using System.Xml.Linq;
using NUnit.Framework;

namespace trx2junit.Tests.Internal.TrxTestResultXmlParserTests
Expand All @@ -7,18 +7,18 @@ namespace trx2junit.Tests.Internal.TrxTestResultXmlParserTests
public class Parse
{
[Test]
[TestCase("./data/trx/mstest.trx" , 3, 3)]
[TestCase("./data/trx/mstest-datadriven.trx", 5, 3)]
[TestCase("./data/trx/mstest-ignore.trx" , 4, 4)]
[TestCase("./data/trx/nunit.trx" , 3, 3)]
[TestCase("./data/trx/nunit-datadriven.trx" , 5, 5)]
[TestCase("./data/trx/nunit-ignore.trx" , 5, 5)]
[TestCase("./data/trx/nunit-memberdata.trx" , 5, 5)]
[TestCase("./data/trx/xunit.trx" , 3, 3)]
[TestCase("./data/trx/xunit-datadriven.trx" , 5, 5)]
[TestCase("./data/trx/xunit-ignore.trx" , 4, 4)]
[TestCase("./data/trx/xunit-memberdata.trx" , 5, 3)]
[TestCase("./data/trx/jsingh-qualitrol.trx" , 0, 131)]
[TestCase("./data/trx/mstest.trx" , 3, 3)]
[TestCase("./data/trx/mstest-datadriven.trx" , 5, 3)]
[TestCase("./data/trx/mstest-ignore.trx" , 4, 4)]
[TestCase("./data/trx/nunit.trx" , 3, 3)]
[TestCase("./data/trx/nunit-datadriven.trx" , 5, 5)]
[TestCase("./data/trx/nunit-ignore.trx" , 5, 5)]
[TestCase("./data/trx/nunit-memberdata.trx" , 5, 5)]
[TestCase("./data/trx/xunit.trx" , 3, 3)]
[TestCase("./data/trx/xunit-datadriven.trx" , 5, 5)]
[TestCase("./data/trx/xunit-ignore.trx" , 4, 4)]
[TestCase("./data/trx/xunit-memberdata.trx" , 5, 3)]
[TestCase("./data/trx/nunit-testresultaggregation.trx", 3, 3)]
public void File_given___correct_counts(string trxFile, int expectedUnitTestResultsCount, int expectedTestDefinitionsCount)
{
XElement trx = XElement.Load(trxFile);
Expand All @@ -35,19 +35,19 @@ public void File_given___correct_counts(string trxFile, int expectedUnitTestResu
}
//---------------------------------------------------------------------
[Test]
[TestCase("./data/trx/mstest.trx" , 3, 1)]
[TestCase("./data/trx/mstest-datadriven.trx" , 5, 2)]
[TestCase("./data/trx/mstest-ignore.trx" , 4, 1)]
[TestCase("./data/trx/mstest-datadriven-no-failures.trx", 5, 0)]
[TestCase("./data/trx/nunit.trx" , 3, 1)]
[TestCase("./data/trx/nunit-datadriven.trx" , 5, 2)]
[TestCase("./data/trx/nunit-ignore.trx" , 5, 1)]
[TestCase("./data/trx/nunit-memberdata.trx" , 5, 2)]
[TestCase("./data/trx/xunit.trx" , 3, 1)]
[TestCase("./data/trx/xunit-datadriven.trx" , 5, 2)]
[TestCase("./data/trx/xunit-ignore.trx" , 4, 1)]
[TestCase("./data/trx/xunit-memberdata.trx" , 5, 2)]
[TestCase("./data/trx/jsingh-qualitrol.trx" , 136, 8)]
[TestCase("./data/trx/mstest.trx" , 3, 1)]
[TestCase("./data/trx/mstest-datadriven.trx" , 5, 2)]
[TestCase("./data/trx/mstest-ignore.trx" , 4, 1)]
[TestCase("./data/trx/mstest-datadriven-no-failures.trx", 5, 0)]
[TestCase("./data/trx/nunit.trx" , 3, 1)]
[TestCase("./data/trx/nunit-datadriven.trx" , 5, 2)]
[TestCase("./data/trx/nunit-ignore.trx" , 5, 1)]
[TestCase("./data/trx/nunit-memberdata.trx" , 5, 2)]
[TestCase("./data/trx/xunit.trx" , 3, 1)]
[TestCase("./data/trx/xunit-datadriven.trx" , 5, 2)]
[TestCase("./data/trx/xunit-ignore.trx" , 4, 1)]
[TestCase("./data/trx/xunit-memberdata.trx" , 5, 2)]
[TestCase("./data/trx/nunit-testresultaggregation.trx" , 3, 1)]
public void File_given___correct_ResultSummary_total_failed(string trxFile, int expectedTotalCount, int expectedFailedCount)
{
XElement trx = XElement.Load(trxFile);
Expand Down
6 changes: 3 additions & 3 deletions tests/trx2junit.Tests/WorkerTests/ConvertAsync.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;
Expand Down Expand Up @@ -46,7 +46,7 @@ static void DeleteFiles(string path, string extension)
[TestCase("./data/trx/xunit-datadriven.trx")]
[TestCase("./data/trx/xunit-ignore.trx")]
[TestCase("./data/trx/xunit-memberdata.trx")]
[TestCase("./data/trx/jsingh-qualitrol.trx")]
[TestCase("./data/trx/nunit-testresultaggregation.trx")]
public async Task Trx_file_given___converted(string trxFile)
{
string junitFile = Path.ChangeExtension(trxFile, "xml");
Expand All @@ -72,7 +72,7 @@ public async Task Trx_file_given___converted(string trxFile)
[TestCase("./data/trx/xunit-datadriven.trx")]
[TestCase("./data/trx/xunit-ignore.trx")]
[TestCase("./data/trx/xunit-memberdata.trx")]
[TestCase("./data/trx/jsingh-qualitrol.trx")]
[TestCase("./data/trx/nunit-testresultaggregation.trx")]
public async Task Trx_file_given___generated_xml_is_valid_against_schema(string trxFile)
{
string junitFile = Path.ChangeExtension(trxFile, "xml");
Expand Down
Loading

0 comments on commit c5eb208

Please sign in to comment.