Parse JunitXML test output

Parse JunitXML test output from any testing framework.

For unit testing frameworks that aren't supported at the Gold or Silver level, you can use the cg junitxml command. This command allows you to parse any Junit XML formatted unit test output for more readability.

The cg junitxml command is installed in CodeGrade's VMs by default. You can also download the cg binaries to run this and other cg commands in your local environment:

Backward Compatibility

This command was previously cg unit-tests junitxml. For better scalability, we have opted to move all type or framework specific commands to the root level such as cg junitxml and cg checkstyle. The cg unit-tests junitxml command will continue to be supported for backward compatibility.

Arguments

The cg junitxml command accepts the following command line arguments:

  • Junit XML file (required) The Junit XML file(s) to be parsed. You can pass multiple Junit XML files to the command. Each file will be parsed and its test cases reported. If scoring is enabled, the scores will be aggregated.

  • --output or -o (optional) The output file to use. If a number is provided it will use that file descriptor. Defaults to file descriptor 3.

  • --no-score (optional) If set, will not output a score based on the parsed Junit XML.

  • --no-parse-weight (optional) If set, will not parse the weight from the test titles.

Example usage

  1. Write the output of your unit test to a Junit XML. The code below illustrates the contents of a typical Junit XML file:

coverage.xml
<?xml version="1.0" encoding="UTF-8" ?>
<testsuites id="Calculator suite" name="empty_name" tests="2" failures="1" time="0.001">
  <testsuite id="uuid1" name="Addition and Multiplication" tests="2" failures="1" time="0.001">
    <testcase id="uuid2" name="[1] Check whether the addition function returns the expected result." time="0.001"></testcase>
    <testcase id="uuid2" name="[2] Check whether the multiply function returns the expected result." time="0.001">
      <failure message="expected: 6.0 but was: 5.0" type="ERROR">
        ERROR: Expected: 6.0 but was: 5.0
        Category: Checking returns - Multiplication
        File: /home/codegrade/student/calculator.py
        Line: 2
      </failure>
    </testcase>
  </testsuite>
</testsuites>
  1. Pass the filename of your Junit XML file as an argument to the cg junitxml command along with any additional options. In this case, we opt to not infer the weight of the test from each test cases name:

cg junitxml coverage.xml --no-parse-weight

Last updated