Git Product home page Git Product logo

xunit-to-junit's Introduction

xUnit.net v2 XML Format to JUnit Format

🚨 If you're using this tool to process test results file(s) after having run dotnet test, I recommend using the JUnit Test Logger instead. The output is better (at least in CircleCI). If you can't install an additional NuGet package in your test project(s), can't modify your build or are processing test results file(s) that have previously been generated, please read on.

Package Release
dotnet-xunit-to-junit NuGet
CI Status Platform(s) Framework(s) Test Framework(s)
GitHub Build Status Ubuntu net6.0, net7.0, net8.0 net6.0, net7.0, net8.0

CircleCI can only parse test results in the JUnit format. This Extensible Stylesheet Language Transformations can transform a xUnit.net v2 XML test results file into a JUnit test results file.

Note: this only handles the easiest use case for the moment, as soon as I encounter issues in real life usage I'll add extra testing scenarios.

Consume the transform

Consume JUnit.xslt through the dotnet-xunit-to-junit NuGet package

dotnet-xunit-to-junit is a .NET global tool:

dotnet tool install -g dotnet-xunit-to-junit
dotnet xunit-to-junit "path-to-xunit-test-results.xml" "desired-path-to-junit-test-results.xml"

Consume JUnit.xslt directly from C#

Note: For .NET Core, this requires nestandard2.0 and above.

// Required using statement
using System.Xml.Xsl;

// Change the value of these three variables
const string inputFilePath = "C:/tmp/xunit.xml";
const string outputFilePath = "C:/tmp/junit.xml";
const string xsltFilePath = "C:/tmp/JUnit.xslt";

var xlsTransform = new XslCompiledTransform();
xlsTransform.Load(xsltFilePath);

var writerSettings = xlsTransform.OutputSettings.Clone();
// Save without BOM, CircleCI can't read test results files starting with a BOM
writerSettings.Encoding = new UTF8Encoding(false);

using (var stream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write))
using (var results = XmlWriter.Create(stream, writerSettings))
{
    xlsTransform.Transform(inputFilePath, results);
}

Building locally

Run this command to build on Windows:

.\build.ps1

Run this command to build on Linux / macOS:

./build.sh

If you want to pack the .NET Global Tool, you can run .\build.ps1 --package.

xunit-to-junit's People

Contributors

dependabot[bot] avatar gabrielweyer avatar hggeorg avatar longhronshen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xunit-to-junit's Issues

Error during dotnet tool install

Hello, thank you a lot for the nice tooling.
I'm trying to install dotnet-xunit-to-junit dotnet tool, but receive an error:

dotnet tool install dotnet-xunit-to-junit
warning NU3028: Package 'dotnet-xunit-to-junit 2.0.2' from source 'https://api.nuget.org/v3/index.json': The repository primary signature's timestamp found a chain building issue: ExplicitDistrust: The trust setting for this policy was set to Deny.
error NU3037: Package 'dotnet-xunit-to-junit 2.0.2' from source 'https://api.nuget.org/v3/index.json': The repository primary signature validity period has expired.
The tool package could not be restored.
Tool 'dotnet-xunit-to-junit' failed to install. 

I suppose there is something wrong with the dotnet-xunit-to-junit as other tools install successfully .

As a workaround I played with trusted certificates settings in Nuget.config and was able to install dotnet-xunit-to-junit tool, but wonder why it failed initially. Certificate fingerprints are taken from dotnet tool install dotnet-xunit-to-junit -v diag output

Problem with convert xunit tests with different InlineData

Problem

Wrong name (the same name) when the unit test has a lot of InlineData. The name should contain information about the inline data. Important: InlineData contains polish characters with diacritics.

Actual data

Input:

<!-- ... -->
<test name="UnitTestsProject.PolishCharacterMapperTests.Schould_Map2Polish_returns_valid_mapped_string(input: \&quot;A\&quot;, output: \&quot;[AaĄą]\&quot;)" type="UnitTestsProject.PolishCharacterMapperTests" method="Schould_Map2Polish_returns_valid_mapped_string" time="0.0000037" result="Pass" />
<test name="UnitTestsProject.PolishCharacterMapperTests.Schould_Map2Polish_returns_valid_mapped_string(input: \&quot;ń\&quot;, output: \&quot;[Ńń]\&quot;)" type="UnitTestsProject.PolishCharacterMapperTests" method="Schould_Map2Polish_returns_valid_mapped_string" time="0.0000042" result="Pass" />
<!-- ... -->

Output: (actual -WRONG)

<!-- ... -->
<testcase name="Schould_Map2Polish_returns_valid_mapped_string" classname="UnitTestsProject.PolishCharacterMapperTests" time="0.0000037" />
<testcase name="Schould_Map2Polish_returns_valid_mapped_string" classname="UnitTestsProject.PolishCharacterMapperTests" time="0.0000042" />
<!-- ... -->

Should look after fix

Output:

<!-- ... -->
<testcase name="Schould_Map2Polish_returns_valid_mapped_string(input: \&quot;ń\&quot;, output: \&quot;[Ńń]\&quot;)" classname="UnitTestsProject.PolishCharacterMapperTests" time="0.0000037" />
<testcase name="Schould_Map2Polish_returns_valid_mapped_string(input: \&quot;ń\&quot;, output: \&quot;[Ńń]\&quot;)" classname="UnitTestsProject.PolishCharacterMapperTests" time="0.0000042" />
<!-- ... -->

Support for dotnet core LTS (2.1)?

Is there a reason not to target dotnet core LTS (2.1)?

Installing on LTS, it gives the error:

C:> dotnet tool install --global dotnet-xunit-to-junit
error NU1202: Package dotnet-xunit-to-junit 1.0.0 is not compatible with netcoreapp2.1 (.NETCoreApp,Version=v2.1) / any. Package dotnet-xunit-to-junit 1.0.0 supports: netcoreapp2.2 (.NETCoreApp,Version=v2.2) / any

Output Junit file doesn't have test name for a test case

Hey,
Thanks for developing this nice tool which helps in uploading test results in CircleCI.
We tried to use this package and upload test results in circleCI run but looks like we have no test case name shown both in ran pipeline and circleCI insights. When looking further into resulted JUnit file, found that there is a test case name printed which we have in the source file (xunit result).

Attaching our sample snipptes of both xunit_result.xml and junit_result.xml (which was generated using this nuget)
Snippet of Xunit_result.xml
image

Snippet of resulting file (junit)
image
In the above snippet, test case name is blank.

We are using 'XunitXml.TestLogger' nuget to generate the xunit result XML.
Could you please guide us on how to resolve this, without the test name in the JUnit file, circleCI shows blank rows under the test case name column.
Your response is highly appreciated !!

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.