SonarQube cannot parse TEST-report.xml which contains any failures

萝らか妹 提交于 2021-02-05 10:40:01

问题


How to send the XML report to SonarQube? I mean, while the TEST-report.xml file contains any failures, the import operation fails. I got an error:

Running SonarQube using SonarQube Runner.17:18:18.452 ERROR: Error during SonarScanner execution
java.lang.NullPointerException
    at java.text.DecimalFormat.parse(DecimalFormat.java:2030)
    at java.text.NumberFormat.parse(NumberFormat.java:383)
    ...

The TEST-report.xml file (JUnit) contains something like:

<?xml version='1.0' encoding='UTF-8'?>
<testsuites name='X UITests.xctest' tests='12' failures='3'>
  <testsuite name='X.MoreViewTests' tests='1' failures='1'>
    <testcase classname='X.MoreViewTests' name='testSucceed_allAction'>
      <failure message='XCTAssertTrue failed'>X UITests/Cases/Bottom Navigation/MoreViewTests.swift:212</failure>
    </testcase>
  </testsuite>
  <testsuite name='X.OrderViewTests' tests='1' failures='0'>
    <testcase classname='X.OrderViewTests' name='testSucceed_allAction' time='68.570'/>
  </testsuite>
</testsuites>

But when I removed the failure lines, becomes:

<?xml version='1.0' encoding='UTF-8'?>
<testsuites name='X UITests.xctest' tests='12' failures='3'>
  <testsuite name='X.OrderViewTests' tests='1' failures='0'>
    <testcase classname='X.OrderViewTests' name='testSucceed_allAction' time='68.570'/>
  </testsuite>
</testsuites>

It works. Any idea? Thanks.


回答1:


Your XML report is invalid (doesn't meet the Surefire XML format requirements).

testsuite required parameters:

  • name - Full class name of the test for non-aggregated testsuite documents. Class name without the package for aggregated testsuites documents
  • tests - The total number of tests in the suite
  • failures - The total number of tests in the suite that failed. A failure is a test which the code has explicitly failed by using the mechanisms for that purpose. e.g., via an assertEquals
  • errors - The total number of tests in the suite that errored. An errored test is one that had an unanticipated problem. e.g., an unchecked throwable; or a problem with the implementation of the test
  • skipped - The total number of ignored or skipped tests in the suite

The exception starts with DecimalFormat.parse

java.lang.NullPointerException
    at java.text.DecimalFormat.parse(DecimalFormat.java:2030)
    at java.text.NumberFormat.parse(NumberFormat.java:383)

which means that the XML report parser couldn't parse a number. You have two missing parameters: errors and skipped. I don't know how you generate these reports (which JUnit version etc.), but probably the used tool is outdated or miss-configured.



来源:https://stackoverflow.com/questions/65232811/sonarqube-cannot-parse-test-report-xml-which-contains-any-failures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!