JUnit parser failing to find or parse test results
Problem
JUnit parser failing to find or parse test results.
The following appear in Bamboo or agent's log:
2017-12-25 16:55:25,938 INFO [18-BAM::Local Agent 2::Agent:pool-33-thread-1] [TaskExecutorImpl] PLAN-KEY-JOB-2: Starting task 'Parse test results' of type 'com.atlassian.bamboo.plugins.testresultparser:task.testresultparser.junit'
2017-12-25 16:55:26,657 ERROR [pool-37-thread-1] [TestCollationServiceImpl] PLAN-KEY-JOB-2: Failed to parse test result file "C:\Atlassian\ApplicationData\Bamboo\xml-data\build-dir\PLAN-KEY-JOB\test_results.xml"
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at com.atlassian.bamboo.build.test.junit.JunitTestResultsParser.parse(JunitTestResultsParser.java:96)
at com.atlassian.bamboo.build.test.junit.JunitTestResultsParser.parse(JunitTestResultsParser.java:85)
at com.atlassian.bamboo.build.test.junit.JunitTestReportCollector.collect(JunitTestReportCollector.java:42)
at com.atlassian.bamboo.build.test.TestCollationServiceImpl$1$1.run(TestCollationServiceImpl.java:129)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Diagnosis
- Make sure your test result was created in the build failing or you have the option Advanced options >> Pick up test results that were created outside of this build set in your JUnit parser task.
- Your test result encoding is not configured to ASCII or UTF8 without BOM
One of the following messages are showing up in your build logs:
simple 02-Aug-2017 13:59:36 Parsing test results under E:\bamboo_home\xml-data\build-dir\PLAN-KEY-JOB... error 02-Aug-2017 13:59:36 Failed to parse test result file "E:\bamboo_home\xml-data\build-dir\PLAN-KEY-JOB\test_results.xml"
simple 02-Aug-2017 13:57:03 Parsing test results under E:\bamboo_home\xml-data\build-dir\PLAN-KEY-JOB... simple 02-Aug-2017 13:57:03 Failing task since test cases were expected but none were found.
Cause
The encoding is not correctly configured to ASCII or UTF8 without BOM
Resolution
Convert your file encoding to ASCII or UTF8 without BOM
In Unix like systems you should be change the encoding and remove the BOM using uconv:
Find the original encoding using file
file <YOUR_TEST_RESULT_FILE>
Check that uconv can recognise this encoding.
uconv --list
Convert from the original encoding and remove the BOM using the --remove-signature option.
mv results.junit.xml results.juxit.xml.orig uconv -f <GIVEN_ENCODING> -t UTF-8 results.junit.xml.orig --remove-signature -o results.junit.xml
In Windows you can use the following command to fix it:
$MyPath = '${bamboo.build.working.directory}\path\to\filename' $MyFile = Get-Content $MyPath $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding($False) [System.IO.File]::WriteAllLines($MyPath, $MyFile, $Utf8NoBomEncoding)