From 4128d36b9238297063f2ac18b871b325d5fd22a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81dric=20Luthi?= Date: Sun, 22 Jun 2025 16:22:35 +0200 Subject: [PATCH] Use "Unclassified" when no class name is available Fixes #556 --- __tests__/__outputs__/dotnet-xunitv3.md | 26 +++++++ .../__snapshots__/dotnet-trx.test.ts.snap | 70 +++++++++++++++++++ dist/index.js | 2 +- src/parsers/dotnet-trx/dotnet-trx-parser.ts | 2 +- 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 __tests__/__outputs__/dotnet-xunitv3.md diff --git a/__tests__/__outputs__/dotnet-xunitv3.md b/__tests__/__outputs__/dotnet-xunitv3.md new file mode 100644 index 0000000..f27f9e2 --- /dev/null +++ b/__tests__/__outputs__/dotnet-xunitv3.md @@ -0,0 +1,26 @@ +![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%203%20failed-critical) +|Report|Passed|Failed|Skipped|Time| +|:---|---:|---:|---:|---:| +|[fixtures/dotnet-xunitv3.trx](#user-content-r0)|1 ✅|3 ❌||267ms| +## ❌ fixtures/dotnet-xunitv3.trx +**4** tests were completed in **267ms** with **1** passed, **3** failed and **0** skipped. +|Test suite|Passed|Failed|Skipped|Time| +|:---|---:|---:|---:|---:| +|[DotnetTests.XUnitV3Tests.FixtureTests](#user-content-r0s0)|1 ✅|1 ❌||18ms| +|[Unclassified](#user-content-r0s1)||2 ❌||0ms| +### ❌ DotnetTests.XUnitV3Tests.FixtureTests +``` +❌ Failing_Test + Assert.Null() Failure: Value is not null + Expected: null + Actual: Fixture { } + at DotnetTests.XUnitV3Tests.FixtureTests.Failing_Test() in /_/reports/dotnet/DotnetTests.XUnitV3Tests/FixtureTests.cs:line 25 + at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) + at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) +✅ Passing_Test +``` +### ❌ Unclassified +``` +❌ [Test Class Cleanup Failure (DotnetTests.XUnitV3Tests.FixtureTests.Failing_Test)] +❌ [Test Class Cleanup Failure (DotnetTests.XUnitV3Tests.FixtureTests.Passing_Test)] +``` \ No newline at end of file diff --git a/__tests__/__snapshots__/dotnet-trx.test.ts.snap b/__tests__/__snapshots__/dotnet-trx.test.ts.snap index 46c8601..f432162 100644 --- a/__tests__/__snapshots__/dotnet-trx.test.ts.snap +++ b/__tests__/__snapshots__/dotnet-trx.test.ts.snap @@ -135,6 +135,76 @@ Actual: False } `; +exports[`dotnet-trx tests matches dotnet-xunitv3 report snapshot 1`] = ` +TestRunResult { + "path": "fixtures/dotnet-xunitv3.trx", + "suites": [ + TestSuiteResult { + "groups": [ + TestGroupResult { + "name": null, + "tests": [ + TestCaseResult { + "error": { + "details": "Assert.Null() Failure: Value is not null +Expected: null +Actual: Fixture { } + at DotnetTests.XUnitV3Tests.FixtureTests.Failing_Test() in /_/reports/dotnet/DotnetTests.XUnitV3Tests/FixtureTests.cs:line 25 + at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) + at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)", + "line": 25, + "message": "Assert.Null() Failure: Value is not null +Expected: null +Actual: Fixture { } + at DotnetTests.XUnitV3Tests.FixtureTests.Failing_Test() in /_/reports/dotnet/DotnetTests.XUnitV3Tests/FixtureTests.cs:line 25 + at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) + at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)", + "path": "DotnetTests.XUnitV3Tests/FixtureTests.cs", + }, + "name": "Failing_Test", + "result": "failed", + "time": 17.0545, + }, + TestCaseResult { + "error": undefined, + "name": "Passing_Test", + "result": "success", + "time": 0.8786, + }, + ], + }, + ], + "name": "DotnetTests.XUnitV3Tests.FixtureTests", + "totalTime": undefined, + }, + TestSuiteResult { + "groups": [ + TestGroupResult { + "name": null, + "tests": [ + TestCaseResult { + "error": undefined, + "name": "[Test Class Cleanup Failure (DotnetTests.XUnitV3Tests.FixtureTests.Failing_Test)]", + "result": "failed", + "time": 0, + }, + TestCaseResult { + "error": undefined, + "name": "[Test Class Cleanup Failure (DotnetTests.XUnitV3Tests.FixtureTests.Passing_Test)]", + "result": "failed", + "time": 0, + }, + ], + }, + ], + "name": "Unclassified", + "totalTime": undefined, + }, + ], + "totalTime": 267, +} +`; + exports[`dotnet-trx tests matches report snapshot (only failed tests) 1`] = ` TestRunResult { "path": "fixtures/dotnet-trx.trx", diff --git a/dist/index.js b/dist/index.js index b7ca089..a5ea165 100644 --- a/dist/index.js +++ b/dist/index.js @@ -974,7 +974,7 @@ class DotnetTrxParser { })); const testClasses = {}; for (const r of unitTestsResults) { - const className = r.test.TestMethod[0].$.className; + const className = r.test.TestMethod[0].$.className ?? "Unclassified"; let tc = testClasses[className]; if (tc === undefined) { tc = new TestClass(className); diff --git a/src/parsers/dotnet-trx/dotnet-trx-parser.ts b/src/parsers/dotnet-trx/dotnet-trx-parser.ts index 826d27c..48a383f 100644 --- a/src/parsers/dotnet-trx/dotnet-trx-parser.ts +++ b/src/parsers/dotnet-trx/dotnet-trx-parser.ts @@ -81,7 +81,7 @@ export class DotnetTrxParser implements TestParser { const testClasses: {[name: string]: TestClass} = {} for (const r of unitTestsResults) { - const className = r.test.TestMethod[0].$.className + const className = r.test.TestMethod[0].$.className ?? "Unclassified" let tc = testClasses[className] if (tc === undefined) { tc = new TestClass(className)