Skip to content

Add JUnitSerializer with bidirectional serialization and format conversion support#24

Merged
Malcolmnixon merged 6 commits intomainfrom
copilot/add-junit-serializer-class
Dec 17, 2025
Merged

Add JUnitSerializer with bidirectional serialization and format conversion support#24
Malcolmnixon merged 6 commits intomainfrom
copilot/add-junit-serializer-class

Conversation

Copy link
Contributor

Copilot AI commented Dec 16, 2025

JUnit Serializer Implementation - Complete ✓

  • Create JUnitSerializer.cs in src/DemaConsulting.TestResults/IO/
    • Implement Serialize method that converts TestResults to JUnit XML format
    • Implement Deserialize method that converts JUnit XML back to TestResults
    • Map TestResult properties to JUnit XML elements (testsuites, testsuite, testcase)
    • Handle different test outcomes (passed, failed, error, skipped)
    • Include system-out and system-err output
    • Use UTF-8 encoding like TrxSerializer
    • Support format conversion between TRX and JUnit
  • Create JUnitSerializerTests.cs in test/DemaConsulting.TestResults.Tests/IO/
    • Test basic serialization with passed tests
    • Test serialization with failed tests (error message and stack trace)
    • Test serialization with system output and error
    • Test serialization with multiple test results
    • Test serialization with different test outcomes
    • Test basic deserialization
    • Test deserialization with failures, errors, and skipped tests
    • Test deserialization with system output
    • Test deserialization with multiple test suites
    • Test round-trip serialization and deserialization
  • Run tests to validate implementation (25 tests pass, 0 failed)
  • Run build to ensure no warnings (0 warnings, 0 errors)
  • Request code review (completed)
  • Run security scanning with CodeQL (0 vulnerabilities found)
  • Update documentation (README.md, ARCHITECTURE.md, SECURITY.md, AGENTS.md)
  • Fix spelling issues in variable names

Summary

Successfully implemented JUnitSerializer with bidirectional serialization and format conversion capabilities:

Code Changes:

  • JUnitSerializer with Serialize and Deserialize methods (full TRX-like architecture)
  • 16 comprehensive tests covering all serialization and deserialization scenarios
  • All 25 tests pass (17 original + 8 new), builds clean with no warnings
  • No security vulnerabilities detected
  • Supports round-trip conversion and format conversion (TRX ↔ JUnit)

Documentation Updates:

  • README.md: Added JUnit format to features, included JUnit usage example and format conversion examples
  • ARCHITECTURE.md: Documented JUnitSerializer with bidirectional serialization capability
  • SECURITY.md: Updated security best practices to include JUnit files
  • AGENTS.md: Updated to reflect support for both TRX and JUnit formats

Format Conversion Support

The implementation enables seamless conversion between TRX and JUnit formats:

  • Read JUnit XML → Convert to TRX
  • Read TRX → Convert to JUnit XML
  • Round-trip conversion preserves test data accurately
Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: Serialize to JUnit</issue_title>
<issue_description>### Problem Statement

I would like the ability to serialize test results to JUnit XML files.

Proposed Solution

Add a new JUnitSerializer static class in src/DemaConsulting.TestResults/IO architected almost identically to the TrxSerializer class.

Just like the TrxSerializer, this class would have a public static Serialize method that would take a TestResults object and return a string, but the string would contain the results in JUnit XML format.

The JUnitSerializer would need to map the TestResult properties to appropriate JUnit fields. As JUnit is a simpler format, that mapping may involve dropping some fields (such as CodeBase) if no appropriate JUnit fields exist.

Alternatives Considered

None

Usage Examples

using DemaConsulting.TestResults;
using DemaConsulting.TestResults.IO;

// Create a TestResults instance
var results = new TestResults { Name = "SomeTests" };

// Add some results
results.Results.Add(
    new TestResult
    {
        Name = "Test1",
        ClassName = "SomeTestClass",
        CodeBase = "MyTestAssembly",
        Outcome = TestOutcome.Passed,
        Duration = TimeSpan.FromSeconds(1.5),
        StartTime = DateTime.UtcNow,
        EndTime = DateTime.UtcNow.AddSeconds(1.5)
    });

results.Results.Add(
    new TestResult
    {
        Name = "Test2",
        ClassName = "SomeTestClass",
        CodeBase = "MyTestAssembly",
        Outcome = TestOutcome.Failed,
        ErrorMessage = "Expected value to be 42 but was 0",
        ErrorStackTrace = "at SomeTestClass.Test2() in Test.cs:line 15"
    });

// Save the results to JUnit file
File.WriteAllText(
    "results.xml",
    JUnitSerializer.Serialize(results));

Benefits

Some tools want to consume their results as JUnit files. This would allow supporting those tools directly rather than using an external converter tool such as gfoidl/trx2junit.

Priority

Medium - Would improve my workflow

Willingness to Contribute

Yes, I can submit a pull request

Additional Context

No response

Checklist

  • I have searched existing issues to ensure this is not a duplicate
  • I have provided a clear description of the feature
  • I have explained why this feature would be useful</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copilot AI changed the title [WIP] Add JUnitSerializer class for test results serialization Add JUnitSerializer for exporting test results to JUnit XML format Dec 16, 2025
Copilot AI requested a review from Malcolmnixon December 16, 2025 19:24
Copy link
Contributor

@Malcolmnixon Malcolmnixon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README.md and ARCHITECTURE.md files should be updated to reflect both TRX and JUnit files supported. Please review any other documentation files for similar updates.

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 16, 2025

The README.md and ARCHITECTURE.md files should be updated to reflect both TRX and JUnit files supported. Please review any other documentation files for similar updates.

Updated all documentation files to reflect support for both TRX and JUnit formats:

  • README.md: Added JUnit to features list, included JUnit usage example alongside TRX example
  • ARCHITECTURE.md: Documented JUnitSerializer in the serialization layer section, updated data flow and future considerations
  • SECURITY.md: Updated security best practices to reference test result files (both TRX and JUnit)
  • AGENTS.md: Updated to reflect support for both formats

Commit: 4f23605

Copy link
Contributor

@Malcolmnixon Malcolmnixon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation suggests the library can be used to convert between formats. This is a nice goal, but would require the JUnitSerializer add a Deserialize method.

Please implement a JUnitSerializer.Deserialize method with appropriate tests and add any appropriate documentation updates.

Copilot AI and others added 2 commits December 16, 2025 19:50
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 16, 2025

The documentation suggests the library can be used to convert between formats. This is a nice goal, but would require the JUnitSerializer add a Deserialize method.

Please implement a JUnitSerialize...

Implemented JUnitSerializer.Deserialize() method with comprehensive test coverage:

Implementation:

  • Parses JUnit XML (both single testsuite and testsuites root elements)
  • Maps JUnit outcomes back to TestOutcome (failure→Failed, error→Error, skipped→NotExecuted)
  • Extracts error messages, stack traces, and system output
  • Handles "DefaultSuite" conversion back to empty class names

Tests (8 new):

  • Basic deserialization
  • Deserialization with failures, errors, and skipped tests
  • Deserialization with system output
  • Multiple test suites
  • Round-trip serialization/deserialization

Documentation:

  • Added format conversion examples to README.md showing TRX ↔ JUnit conversion
  • Updated ARCHITECTURE.md to mention deserialization capability

All 25 tests pass with 0 warnings. Commits: 4e94fc4 (implementation), 5817a62 (documentation)

Copilot AI changed the title Add JUnitSerializer for exporting test results to JUnit XML format Add JUnitSerializer with bidirectional serialization and format conversion support Dec 16, 2025
Copilot AI requested a review from Malcolmnixon December 16, 2025 19:55

// Verify first test
var origTest1 = original.Results[0];
var deserTest1 = deserialized.Results[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"deser" is considered a spelling mistake - this should probably be expanded to the full "deserialized" name. Please ensure the PR succeeds building.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed variable naming by expanding "deser" to "deserialized". Changed deserTest1deserializedTest1 and deserTest2deserializedTest2. Build succeeds with 0 warnings, all 25 tests pass.

Commit: d18dd1d

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
@Malcolmnixon Malcolmnixon marked this pull request as ready for review December 17, 2025 19:24
@Malcolmnixon Malcolmnixon merged commit ec2a0dd into main Dec 17, 2025
8 checks passed
@Malcolmnixon Malcolmnixon deleted the copilot/add-junit-serializer-class branch December 17, 2025 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Serialize to JUnit

2 participants