JUnit Parser task in Bamboo shows 'Failed to parse test result file' error when parsing test results file
Problem
When running the JUnit Response Parser task in Bamboo in a previously generated XML test results file, you may get the following error:
Failed to parse test result file /working_dir/tests_results.xml
Cause
As the error states, Bamboo is unable to parse the test file. This may be caused by:
- Incorrect XML format
- Invalid characters in the file
Diagnosis and Fix
To fix this problem, it's necessary to identify what in the file is not correct and either make sure it's correctly generated so Bamboo can identify it correctly or add a previous task to fix it (you can use a script task for it). This may include some trial and error.
- Validate the generate XML file, to be sure it's in a correct XML format
- Check if it's generated in a correct JUnit format
Run the following command to check the file (this may show invalid characters in the file):
xmllint --noout (--schema schema.xsd) test_results.xml
Run the following command to remove any unprintable characters:
strings test_results.xml > fixed_test_results.xml
This command may remove characters you didn't expect to be removed or add new lines characters. This is better used as a diagnosis tool (apply and see if fixed) then a definitive fix. You can compare the two files using this command:
diff test_results.xml fixed_test_results.xml