From 249e1247466a4d57c6d2f25ebf8bd15a22457a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Wed, 14 Nov 2018 00:26:21 +0100 Subject: [PATCH 1/2] Test to reproduce the issue [skip ci] --- .../Internal/TrxParserTests/Parse.cs | 8 +++++++ tests/trx2junit.Tests/WorkerTests/Convert.cs | 2 ++ tests/trx2junit.Tests/data/nunit-no-tests.trx | 22 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/trx2junit.Tests/data/nunit-no-tests.trx diff --git a/tests/trx2junit.Tests/Internal/TrxParserTests/Parse.cs b/tests/trx2junit.Tests/Internal/TrxParserTests/Parse.cs index 9764da1..e5f6ce0 100644 --- a/tests/trx2junit.Tests/Internal/TrxParserTests/Parse.cs +++ b/tests/trx2junit.Tests/Internal/TrxParserTests/Parse.cs @@ -15,6 +15,14 @@ public void Parse_NUnit___OK() } //--------------------------------------------------------------------- [Test] + public void Parse_NUnit_with_no_tests___OK() + { + Models.Test actual = this.ParseCore("./data/nunit-no-tests.trx"); + + Assert.IsNotNull(actual); + } + //--------------------------------------------------------------------- + [Test] public void Parse_MsTest___OK() { Models.Test actual = this.ParseCore("./data/mstest.trx"); diff --git a/tests/trx2junit.Tests/WorkerTests/Convert.cs b/tests/trx2junit.Tests/WorkerTests/Convert.cs index d51fb57..6b1b100 100644 --- a/tests/trx2junit.Tests/WorkerTests/Convert.cs +++ b/tests/trx2junit.Tests/WorkerTests/Convert.cs @@ -11,6 +11,7 @@ public class Convert [TestCase("./data/nunit.trx")] [TestCase("./data/mstest.trx")] [TestCase("./data/mstest-warning.trx")] + [TestCase("./data/nunit-no-tests.trx")] public async Task File_given___converted(string trxFile) { string junitFile = Path.ChangeExtension(trxFile, "xml"); @@ -28,6 +29,7 @@ public async Task File_given___converted(string trxFile) [TestCase("./data/nunit.trx")] [TestCase("./data/mstest.trx")] [TestCase("./data/mstest-warning.trx")] + [TestCase("./data/nunit-no-tests.trx")] public async Task File_given___generated_xml_is_valid_against_schema(string trxFile) { string junitFile = Path.ChangeExtension(trxFile, "xml"); diff --git a/tests/trx2junit.Tests/data/nunit-no-tests.trx b/tests/trx2junit.Tests/data/nunit-no-tests.trx new file mode 100644 index 0000000..1df8183 --- /dev/null +++ b/tests/trx2junit.Tests/data/nunit-no-tests.trx @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + NUnit Adapter 3.11.0.0: Test execution startedRunning all tests in /root/repo/tests/my/bin/Release/netcoreapp2.1/my.dll NUnit couldn't find any tests in /root/repo/tests/my/bin/Release/netcoreapp2.1/my.dll NUnit Adapter 3.11.0.0: Test execution complete + + + + No test is available in /root/repo/tests/my/bin/Release/netcoreapp2.1/my.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again. + + + + \ No newline at end of file From 278aa4c76695ea557974fa2a7ce9a89385c75280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Wed, 14 Nov 2018 00:26:52 +0100 Subject: [PATCH 2/2] Tolerate non-existing values in parser --- source/trx2junit/Internal/TrxParser.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/trx2junit/Internal/TrxParser.cs b/source/trx2junit/Internal/TrxParser.cs index 2f3d54a..e479a71 100644 --- a/source/trx2junit/Internal/TrxParser.cs +++ b/source/trx2junit/Internal/TrxParser.cs @@ -65,6 +65,8 @@ private void ReadTestDefinitions() { XElement xTestDefinitions = _trx.Element(s_XN + "TestDefinitions"); + if (xTestDefinitions == null) return; + foreach (XElement xUnitTest in xTestDefinitions.Elements()) { var testDefinition = new TestDefinition @@ -83,6 +85,8 @@ private void ReadUnitTestResults() { XElement xResults = _trx.Element(s_XN + "Results"); + if (xResults == null) return; + foreach (XElement xResult in xResults.Elements()) { var unitTestResult = new UnitTestResult