Last active
August 18, 2024 08:23
-
-
Save jrreed/f42938492dcf77fe1a4e43ecf2d62bc3 to your computer and use it in GitHub Desktop.
Convert Unity test results XML file into proper NUnit format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Usage: ./fix-unity-test-results.sh | |
# | |
# Unity uses NUnit under the hood for its test framework. Their command line tool outputs a NUnit | |
# test result XML file. See documentation: | |
# * https://github.com/nunit/docs/wiki/Test-Result-XML-Format#test-suite | |
# | |
# The format of this file is currently incorrect. The root element for NUnit XML test results files | |
# should be a '<test-run>' tag, which is missing from Unity's test results file. See issue on forum: | |
# * https://forum.unity3d.com/threads/unity-test-tools.218287/page-6#post-3188590 | |
# | |
# This script uses the XMLStarlet command line tool and 'script/build/fix-unity-test-results.xslt' | |
# to convert the incorrect test results XML file into the correct format. This allows the Jenkins | |
# NUnit plugin to convert the NUnit test results file into a JUnit test results file so Jenkins can | |
# understand and record test results. | |
# | |
set -euo pipefail | |
xml tr fix-unity-test-results.xslt unity-test-results.xml > nunit-test-results.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" cdata-section-elements="message"/> | |
<xsl:strip-space elements="*"/> | |
<xsl:template match="/"> | |
<test-run id="2" engine-version="3.0" clr-version="4.0"> | |
<xsl:copy-of select="(test-suite/@*)[contains('|testcasecount|result|start-time|end-time|duration|total|passed|failed|inconclusive|skipped|asserts|', concat('|', name(), '|'))]" /> | |
<xsl:apply-templates select="@*|node()"/> | |
</test-run> | |
</xsl:template> | |
<xsl:template match="node()|@*"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*|node()"/> | |
</xsl:copy> | |
</xsl:template> | |
</xsl:stylesheet> |
Been awhile but, I want to mention that with the current version I'm using 1.4.5 the root tag has been corrected to <test-run>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the related Unity forum post