- Home /
TeamCity XML Report Processing can not parse Unity 5.6 test results
I am using TeamCity to automate build and test Unity project. For testing I use the command
Unity.exe -runTests -projectPath PATH_TO_YOUR_PROJECT -testResults C:\temp\results.xml -testPlatform editmode
The test result schema is not parse-able by TeamCity XML Report Processing, the error is
Builds/Android/BuildLogs/editmode-results.xml: must contain "test-results", "test-run" or "stack-trace" root element. Please check the NUnit sources for the supported XML Schema.
The actual root element Unity generates is
test-suite not test-run
so TeamCity can not parse it.
Anyone has this problem with TeamCity and Unity ?
Answer by Tomek-Paszek · May 29, 2017 at 09:47 AM
Hi @anngo, I believe it's an oversite from our side. We will try to fix it. For now I can recommend you wrapping the result xml in before it's parsed by TeamCity
Answer by spav5 · Aug 09, 2017 at 12:43 PM
Hi, I am from TeamCity team.
What is the status of this problem in Unity?
At the moment, we expect test results in the following format: http://nunit.org/files/testresult_30.txt
Of course we could provide a workaround and treat root element similar to <test-run/> but since the format is vague enough we'd rather wait for you guys to fix this problem, especially if you plan to do that in the nearest future.
Hi @spav5
Thanks for your interest.
We are fixing this atm so no workaround should hopefully be needed.
Until the fix are out, wrapping the result file with the missing node should solve the issue
We will write here what patch the fix will be in when I know. But we will be backporting it to 5.6 where the issue started.
Any updates and idea when this will be fixed? $$anonymous$$aybe adding a parameter to select the type of output would help?
Answer by Kleptine · Oct 01, 2017 at 05:58 AM
I've written a quick Powershell script to fix the file for the time being. Seems to work well enough:
# Windows Only
# Runs automated tests through the headless Unity runner, and then transforms the output file to
# proper NUnit scheme (or at least the one TeamCity accepts)
# Uncomment to print each command as we go
#Set-PSDebug -Step
try {
# Find our project path
$tools_dir = Split-Path $MyInvocation.MyCommand.Path
$project_dir = Join-Path $tools_dir "/../" -resolve
$results_file = Join-Path $project_dir "results.xml"
# Query the assembly function to generate the project
$exitCode = [Diagnostics.Process]::Start("C:\Program Files\Unity\Editor\Unity.exe",
"-batchmode -runTests -logFile ./logfile.txt -projectPath $project_dir -testResults $results_file -testPlatform playmode").WaitForExit(60000) # Wait for 60 seconds
[xml]$xml = (Get-Content $results_file)
$test_suite = $xml."test-suite"
$wrapper = $xml.CreateElement("test-run")
foreach($attr in $test_suite.Attributes)
{
$wrapper.SetAttribute($attr.Name, $attr.Value)
}
$wrapper.AppendChild($test_suite)
$xml.RemoveAll()
$xml.AppendChild($wrapper)
$xml.Save($results_file)
} Catch {
$ErrorMessage = $_.Exception.Message
Write-Output $ErrorMessage
exit(1)
}