DemaConsulting.TestResults
1.2.0
Prefix Reserved
See the version list below for details.
dotnet add package DemaConsulting.TestResults --version 1.2.0
NuGet\Install-Package DemaConsulting.TestResults -Version 1.2.0
<PackageReference Include="DemaConsulting.TestResults" Version="1.2.0" />
<PackageVersion Include="DemaConsulting.TestResults" Version="1.2.0" />
<PackageReference Include="DemaConsulting.TestResults" />
paket add DemaConsulting.TestResults --version 1.2.0
#r "nuget: DemaConsulting.TestResults, 1.2.0"
#:package DemaConsulting.TestResults@1.2.0
#addin nuget:?package=DemaConsulting.TestResults&version=1.2.0
#tool nuget:?package=DemaConsulting.TestResults&version=1.2.0
TestResults Library
A lightweight C# library for programmatically creating test result files in TRX and JUnit formats.
Features
- âĻ Simple API - Intuitive and easy-to-use object model
- ðŊ Type-Safe - Strongly-typed C# classes for test results
- ðŠķ Lightweight - Minimal external dependencies
- ð Multi-Target - Supports .NET 8, 9, and 10
- ðĶ NuGet Ready - Easy integration via NuGet package
- ð Multiple Formats - Supports both TRX and JUnit XML formats
- â Compatible - Works with Visual Studio, Azure DevOps, and CI/CD systems
Installation
Install via NuGet Package Manager:
dotnet add package DemaConsulting.TestResults
Or via Package Manager Console:
Install-Package DemaConsulting.TestResults
Quick Start
Creating Test Result Files
The following code-snippet shows how to create test result files in both TRX and JUnit XML formats:
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
});
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 a TRX file (Visual Studio format)
File.WriteAllText("results.trx", TrxSerializer.Serialize(results));
// Save the results to a JUnit XML file
File.WriteAllText("results.xml", JUnitSerializer.Serialize(results));
Converting Between Formats
The library supports reading and converting between TRX and JUnit formats:
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
var result = new TestResult
{
Name = "TestWithOutput",
ClassName = "MyTests",
CodeBase = "MyAssembly",
Outcome = TestOutcome.Passed,
SystemOutput = "Debug information\nTest completed successfully"
};
Handling Test Failures
var failedResult = new TestResult
{
Name = "FailingTest",
ClassName = "MyTests",
CodeBase = "MyAssembly",
Outcome = TestOutcome.Failed,
ErrorMessage = "Assertion failed: Expected 100, got 50",
ErrorStackTrace = "at MyTests.FailingTest() in Tests.cs:line 42",
SystemError = "Additional error details"
};
Test Outcomes
The library supports the following test outcomes:
Passed- Test passed successfullyFailed- Test failedInconclusive- Test result was inconclusiveNotExecuted- Test was not executedTimeout- Test exceeded timeout limitAborted- Test was abortedUnknown- Test outcome is unknown
Use Cases
This library is useful when you need to:
- 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, Azure DevOps, or CI/CD systems
Documentation
- Architecture - Learn about the library's architecture and design
- Contributing - Guidelines for contributing to the project
- Code of Conduct - Our code of conduct for contributors
Building from Source
# Clone the repository
git clone https://github.com/demaconsulting/TestResults.git
cd TestResults
# Restore tools
dotnet tool restore
# Restore dependencies
dotnet restore
# Build
dotnet build
# Run tests
dotnet test
Requirements
- .NET 8.0, 9.0, or 10.0
Contributing
We welcome contributions! Please see our Contributing Guide for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- ð Report a Bug
- ðĄ Request a Feature
- ðŽ Ask a Question
Acknowledgments
Developed and maintained by DEMA Consulting.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.