Skip to content

[Bug]: JUnit reporter crashes if test arguments contains an "invalid character" #4261

@carl-andersson-at-westermo

Description

Description

When running a test of the form

[Test]
[Arguments("Some valid string")]
[Arguments("A string with an invalid \x04 character")]
public async Task TestSomething(string parameter)
{
   await Assert.That(parameter).IsNotNull();  
}

The test runner will crash with the following exception: Error output: Unhandled exception in AppDomain: System.ArgumentException: '�', hexadecimal value 0x04, is an invalid character.

Expected Behavior

The invalid character should be escaped in the resulting name / the runner should not crash.

Actual Behavior

The runner crashed when running with the JUnit reporter active. The tests behave fine when running from an IDE or without reporting.

Steps to Reproduce

  1. Create a test class with the following test:
[Test]
[Arguments("Some valid string")]
[Arguments("A string with an invalid \x04 character")]
public async Task TestSomething(string parameter)
{
   await Assert.That(parameter).IsNotNull();  
}
  1. Build the associated test project.
  2. Run the tests using a command of the form dotnet test --test-modules <Path to test> --report-trx --results-directory <Path to results>
  3. Observe that the test runner crashes

TUnit Version

1.9.26

.NET Version

.NET 10

Operating System

Linux

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Exit code: -532462766
  Error output: Unhandled exception in AppDomain: System.ArgumentException: '', hexadecimal value 0x04, is an invalid character.
     at System.Xml.XmlEncodedRawTextWriter.WriteAttributeTextBlock(Char* pSrc, Char* pSrcEnd)
     at System.Xml.XmlEncodedRawTextWriter.WriteString(String text)
     at System.Xml.XmlWellFormedWriter.WriteString(String text)
     at System.Xml.XmlWriter.WriteAttributeString(String localName, String value)
     at TUnit.Engine.Xml.JUnitXmlWriter.WriteTestCase(XmlWriter writer, TestNodeUpdateMessage test)
     at TUnit.Engine.Xml.JUnitXmlWriter.WriteTestSuite(XmlWriter writer, IEnumerable`1 tests, String assemblyName, String targetFramework, TestSummary summary, String filter)
     at TUnit.Engine.Xml.JUnitXmlWriter.GenerateXml(IEnumerable`1 testUpdates, String filter)
     at TUnit.Engine.Reporters.JUnitReporter.AfterRunAsync(Int32 exitCode, CancellationToken cancellation)
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunTestAppAsync(CancellationToken testApplicationCancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 122
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 54
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 62
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 74
     at Microsoft.Testing.Platform.Builder.TestApplication.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs:line 227
...
  Unhandled exception. System.ArgumentException: '', hexadecimal value 0x04, is an invalid character.
     at System.Xml.XmlEncodedRawTextWriter.WriteAttributeTextBlock(Char* pSrc, Char* pSrcEnd)
     at System.Xml.XmlEncodedRawTextWriter.WriteString(String text)
     at System.Xml.XmlWellFormedWriter.WriteString(String text)
     at System.Xml.XmlWriter.WriteAttributeString(String localName, String value)
     at TUnit.Engine.Xml.JUnitXmlWriter.WriteTestCase(XmlWriter writer, TestNodeUpdateMessage test)
     at TUnit.Engine.Xml.JUnitXmlWriter.WriteTestSuite(XmlWriter writer, IEnumerable`1 tests, String assemblyName, String targetFramework, TestSummary summary, String filter)
     at TUnit.Engine.Xml.JUnitXmlWriter.GenerateXml(IEnumerable`1 testUpdates, String filter)
     at TUnit.Engine.Reporters.JUnitReporter.AfterRunAsync(Int32 exitCode, CancellationToken cancellation)
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunTestAppAsync(CancellationToken testApplicationCancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 122
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 54
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 62
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 74
     at Microsoft.Testing.Platform.Builder.TestApplication.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs:line 227
...

Additional Context

AOT / Trimming is not in use.

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions