SonarQube Java
  1. SonarQube Java
  2. SONARJAVA-41

Enhance Surefire plugin to read junit xml results that contain nested <testsuite> nodes

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Surefire
    • Labels:
    • Number of attachments :
      0

      Description

      Our junit test report contains several nested <testsuite> nodes. In communicating with the sonar user group I've discovered that the surefire plugin will not handle nested test suite results like these.

      This results in sonar showing zero tests for our project. We'd love to get this enhancement made in a future sonar release!

        Activity

        Hide
        Gligor Mihai added a comment -

        A) The way I fixed this:

        • in the Surefire plugin, in class org.sonar.plugins.surefire.data.SurefireStaxHandler

        old:
        SMInputCursor testCase = testSuite.childCursor(new ElementFilter("testcase"));

        fix:
        SMInputCursor testCase = testSuite.descendantCursor(new ElementFilter("testcase"));

        B) Another issue that I found in the same SurefireStaxHandler:

        • in JUnit reports, the "time" attribute for a <TestCase> is implied, it might not exist, so for this the test duration should be 0, not set to null as it happens after an exception.

        old:
        long duration = getTimeAttributeInMS(testCaseCursor);

        quick fix (or fix getTimeAttributeInMS):

        long duration = 0L;
        if (testCaseCursor.getAttrValue("time") == null)
        status = "skipped";
        else

        { duration = getTimeAttributeInMS(testCaseCursor); }

        I hope these fixes, maybe improved, will included in next releases

        Best regards!

        Show
        Gligor Mihai added a comment - A) The way I fixed this: in the Surefire plugin, in class org.sonar.plugins.surefire.data.SurefireStaxHandler old: SMInputCursor testCase = testSuite.childCursor(new ElementFilter("testcase")); fix: SMInputCursor testCase = testSuite.descendantCursor(new ElementFilter("testcase")); B) Another issue that I found in the same SurefireStaxHandler: in JUnit reports, the "time" attribute for a <TestCase> is implied, it might not exist, so for this the test duration should be 0, not set to null as it happens after an exception. old: long duration = getTimeAttributeInMS(testCaseCursor); quick fix (or fix getTimeAttributeInMS): long duration = 0L; if (testCaseCursor.getAttrValue("time") == null) status = "skipped"; else { duration = getTimeAttributeInMS(testCaseCursor); } I hope these fixes, maybe improved, will included in next releases Best regards!
        Hide
        Freddy Mallet added a comment -

        Guys, could you attach to this ticket some examples of junit xml results to ease the validation of this ticket ? Thanks

        Show
        Freddy Mallet added a comment - Guys, could you attach to this ticket some examples of junit xml results to ease the validation of this ticket ? Thanks

          People

          • Assignee:
            Unassigned
            Reporter:
            Josh Hester
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: