简体   繁体   中英

cobertura-coverage.xml format not supported by SonarQube for unit tests written in javascript

  • Using istanbul and cobertura, I have managed to get a coverage report for my unit test case written in Javascript(Node js) in XML format(cobertura-coverage.xml). But the created xml does not support the format required by SonarQube.
  • I went through many solutions on Stackoverflow but couldn't find one matching my criteria.

Following is the content generated in the cobertura-coverage.xml file -

<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="5"  lines-covered="5"  line-rate="1"  branches-valid="0"  branches-covered="0"  branch-rate="1"  timestamp="1542872388848" complexity="0" version="0.1">
<sources>
  <source>/home/sreenesh/Sreenesh/Other_Projects/test/tests</source>
</sources>
<packages>
  <package name="tests"  line-rate="1"  branch-rate="1" >
  <classes>
     <class name="test1.js"  filename="test1.js"  line-rate="1"  branch-rate="1" >
     <methods>
        <method name="(anonymous_1)"  hits="1"  signature="()V" >
            <lines><line number="4"  hits="1" /></lines>
        </method>
     </methods>
     <lines>
        <line number="1"  hits="1"  branch="false" />
        <line number="2"  hits="1"  branch="false" />
        <line number="4"  hits="1"  branch="false" />
        <line number="5"  hits="1"  branch="false" />
        <line number="6"  hits="1"  branch="false" />
    </lines>
    </class>
  </classes>
  </package>

In above xml, version for coverage generated is '0.1' and this format is not matching for importing it for Coverage in SonarQube.

Sonar analysis is showing following error -

ERROR: Error during SonarQube Scanner execution
ERROR: Error during parsing of the generic coverage report '/home/sreenesh/Sreenesh/Other_Projects/test/tests/cobertura-coverage.xml'. Look at SonarQube documentation to know the expected XML format.
ERROR: Caused by: Unknown XML node, expected "file" but got "sources" at line 4

Please help me with correct steps to generate xml matching the format here . Thanks.

This is because Sonarqube is expecting an LCOV file format and you are providing a Cobertura report file.

If you want to feed Sonar with this kind of file, you'll need to have Covertura plugin installed and provide the file with the param : sonar.cobertura.reportPath=...

Otherwise go for an LCOV file wich is natively supported by Sonarqube

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM