Troubleshooting "invalid testcase element" error when uploading test results

Problem:

When uploading your test results to CircleCI in a job, you may see the following error:

invalid testcase element

This can happen when CircleCI is unable to parse the test results generated by your test runner.

Prerequisites:

Please verify the content of the test resultsby uploading the file as an artifact. This is helpful to verify what is being parsed by CircleCI. Here is an example of how to upload an artifact:

- store_artifacts:
    path: test-results.xml

Solutions:

  • Solution - Use xmlstarlet to manipulate xml element names
    • It will be necessary to modify the element names so that they are accepted by CircleCI's test result parser. One tool that can be used is xmlstarlet.

      Here is an example of a job step that renames the invalid elements flakyFailture, rerunFailure, and flakyError to failure in a file named test.xml:

      - run:
          name: Correct formatting of test results
          command: |
            xmlstarlet ed --inplace --rename '//testsuite/testcase/flakyFailure' -v 'failure' test.xml
            xmlstarlet ed --inplace --rename '//testsuite/testcase/rerunFailure' -v 'failure' test.xml
            xmlstarlet ed --inplace --rename '//testsuite/testcase/flakyError' -v 'failure' test.xml

Outcome:

After adjusting the element names, your test results will be corrected parsed by CircleCI, and the invalid element error will no longer show.

Additional Notes:

The above example shows how to rename specific elements, but there are cases when the nesting of elements is invalid as well. Please refer to the documentation below for more information:

XmlStarlet Reference

Additional Resources: 

Was this article helpful?
0 out of 1 found this helpful

Comments

0 comments

Article is closed for comments.