Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TestResults is a C# library for creating test result files. The library is desig
- **Type-Safe**: Strongly-typed C# objects
- **Cross-Platform**: Supports .NET 8, 9, and 10

The library currently focuses on TRX format, with potential for additional formats in the future.
The library supports both TRX and JUnit XML formats, with potential for additional formats in the future.

## Technologies and Dependencies

Expand Down
28 changes: 19 additions & 9 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
## Overview

The TestResults library is a lightweight C# library designed to programmatically create test result files.
The library currently focuses on the TRX (Test Results) format, with potential for additional formats in the future.
The library supports both TRX (Test Results) and JUnit XML formats.
TRX files are XML-based test result files commonly used by Visual Studio, Azure DevOps, and other Microsoft testing
tools to store and visualize test execution results.
tools, while JUnit XML is widely used across various CI/CD systems and testing frameworks.

## Design Philosophy

Expand Down Expand Up @@ -67,13 +67,23 @@ The `TrxSerializer` class is responsible for converting the domain model into TR
- Produces TRX files compatible with Visual Studio and Azure DevOps
- Handles proper formatting and schema compliance

#### `JUnitSerializer`

The `JUnitSerializer` class is responsible for converting between the domain model and JUnit XML format:

- Uses .NET's built-in XML serialization capabilities
- Produces JUnit XML files compatible with various CI/CD systems and testing tools
- Can deserialize JUnit XML files back into the domain model
- Groups test results by class name into test suites
- Maps test outcomes to JUnit semantics (failure, error, skipped)

## Data Flow

```text
1. User creates TestResults instance
2. User adds TestResult objects to the Results collection
3. User calls TrxSerializer.Serialize() to convert to TRX XML format
4. User saves the XML string to a .trx file
3. User calls TrxSerializer.Serialize() or JUnitSerializer.Serialize() to convert to desired format
4. User saves the XML string to a .trx or .xml file
```

## Design Patterns
Expand All @@ -95,8 +105,8 @@ The library source code is organized in the `/src/DemaConsulting.TestResults/` d
The library is designed to be extended in several ways:

1. **Custom Test Outcomes**: While the standard outcomes cover most scenarios, custom outcomes could be added
2. **Additional Metadata**: The model could be extended to support additional TRX metadata fields
3. **Alternative Serializers**: Additional serializers could be added for other test result formats
2. **Additional Metadata**: The model could be extended to support additional metadata fields
3. **Alternative Serializers**: Additional serializers could be added for other test result formats (NUnit, xUnit, etc.)

## Quality Attributes

Expand Down Expand Up @@ -128,10 +138,10 @@ The library is designed to be extended in several ways:

Potential enhancements that could be considered:

1. **Deserialization**: Add support for reading existing TRX files back into the object model
2. **Additional Formats**: Support for other test result formats (JUnit XML, NUnit XML, etc.)
1. **Deserialization**: Add support for reading existing TRX and JUnit XML files back into the object model
2. **Additional Formats**: Support for other test result formats (NUnit XML, xUnit XML, etc.)
3. **Streaming**: Support for streaming large test result sets to avoid memory issues
4. **Validation**: Add schema validation to ensure generated TRX files are well-formed
4. **Validation**: Add schema validation to ensure generated files are well-formed

## Dependencies

Expand Down
72 changes: 67 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=demaconsulting_TestResults&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=demaconsulting_TestResults)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=demaconsulting_TestResults&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=demaconsulting_TestResults)

A lightweight C# library for programmatically creating TRX (Test Results) files.
A lightweight C# library for programmatically creating test result files in TRX and JUnit formats.

## Features

Expand All @@ -18,6 +18,7 @@ A lightweight C# library for programmatically creating TRX (Test Results) files.
- 🔄 **Multi-Target** - Supports .NET 8, 9, and 10
- 📦 **NuGet Ready** - Easy integration via NuGet package
- ✅ **Compatible** - Generates TRX files compatible with Visual Studio, Azure DevOps, and other Microsoft testing tools
- 📊 **Multiple Formats** - Supports both TRX and JUnit XML formats

## Installation

Expand All @@ -35,6 +36,8 @@ Install-Package DemaConsulting.TestResults

## Quick Start

### Creating TRX Files

The following code-snippet shows how to create a TRX test-results file:

```csharp
Expand Down Expand Up @@ -68,12 +71,71 @@ results.Results.Add(
ErrorStackTrace = "at SomeTestClass.Test2() in Test.cs:line 15"
});

// Save the results to file
// Save the results to TRX file
File.WriteAllText(
"results.trx",
TrxSerializer.Serialize(results));
```

### Creating JUnit XML Files

The following code-snippet shows how to create a JUnit XML test-results file:

```csharp
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",
Outcome = TestOutcome.Passed,
Duration = TimeSpan.FromSeconds(1.5)
});

results.Results.Add(
new TestResult
{
Name = "Test2",
ClassName = "SomeTestClass",
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 XML file
File.WriteAllText(
"results.xml",
JUnitSerializer.Serialize(results));
```

### Converting Between Formats

The library supports reading and converting between TRX and JUnit formats:

```csharp
using DemaConsulting.TestResults.IO;

// Read JUnit XML file
var junitXml = File.ReadAllText("junit-results.xml");
var results = JUnitSerializer.Deserialize(junitXml);

// Convert to TRX format
var trxXml = TrxSerializer.Serialize(results);
File.WriteAllText("converted.trx", trxXml);

// Or convert TRX to JUnit
var trxXml2 = File.ReadAllText("test-results.trx");
var results2 = TrxSerializer.Deserialize(trxXml2);
var junitXml2 = JUnitSerializer.Serialize(results2);
File.WriteAllText("converted.xml", junitXml2);
```

## Advanced Usage

### Capturing Standard Output
Expand Down Expand Up @@ -120,11 +182,11 @@ The library supports the following test outcomes:

This library is useful when you need to:

- Generate TRX files from custom test runners
- Convert test results from other formats to TRX
- Generate TRX or JUnit XML files from custom test runners
- Convert test results between formats (TRX ↔ JUnit)
- Create test reports programmatically
- Aggregate test results from multiple sources
- Build custom testing tools that integrate with Visual Studio or Azure DevOps
- Build custom testing tools that integrate with Visual Studio, Azure DevOps, or CI/CD systems that consume JUnit XML

## Documentation

Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ Historical security advisories can be found in the
When using the TestResults library:

1. **Keep Updated**: Always use the latest version of the library
2. **Validate Input**: If accepting TRX file paths from users, validate and sanitize them
3. **File Permissions**: When writing TRX files, use appropriate file permissions
2. **Validate Input**: If accepting test result file paths from users, validate and sanitize them
3. **File Permissions**: When writing test result files (TRX or JUnit XML), use appropriate file permissions
4. **Error Handling**: Implement proper error handling when using the library
5. **Code Review**: Review any code that uses this library as part of your security practices

Expand Down
Loading
Loading