- Unit Tests but 93% Coverage on 100 lines - Javascript LCOV working but not JUnit

  • Which versions are you using
    • SonarQube™ 8.9.3
    • Scanner 5.2.0
    • JavaScript/TypeScript Code Quality and Security 8.5.0.16762 (javascript)
    • SonarTS 2.1.0.4359 (typescript)
    • XML Code Quality and Security 2.2.0.2973 (xml)
    • Much more but not relevant I think :slight_smile:
  • What are you trying to achieve
    I get everything in SonarQube except the Unit Tests
  • What have you tried so far to achieve this
    I read many topics here and tried many different settings - see below

I set up my Angular project as easy as possible.
Then I added SonarQube as described here: JavaScript/TypeScript/CSS | SonarQube Docs
and Test Coverage & Execution | SonarQube Docs

The Jest configuration is simple, too.

  reporters: ['default', ['jest-junit', { outputFile: './coverage/junit.xml' }]],
  coverageReporters: ['lcov'],

Then I add all reports as properties.

sonar.javascript.lcov.reportPaths="coverage/lcov.info"
sonar.eslint.reportPaths="coverage/eslint.json"
sonar.junit.reportPaths="coverage/junit.xml"

And in SonarQube then I can see mostly everything - except the Unit Tests.

  • Bugs
  • Vulnerabilities
  • Security Hotspots
  • Debt’s
  • Code Smells
  • Coverage (93%, Coverage on 100 Lines to cover) - Unit Tests
  • 0% Duplications on 260 Lines
  • In Issues tab the ESLINT tagged issues are shown

When I try out this things nothing changes.

sonar.javascript.junit.reportPaths="coverage/junit.xml"
sonar.typescript.junit.reportPaths="coverage/junit.xml"
sonar.junit.reportPaths="coverage/junit.xml"

And with that configuration:

sonar.coverageReportPaths="coverage/junit.xml"

I’m getting:

ERROR: Error during parsing of the generic coverage report '/coverage/junit.xml'. Look at SonarQube documentation to know the expected XML format.
ERROR: Caused by: Unknown XML node, expected "coverage" but got "testsuites" at line 2

The junit.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="jest tests" tests="2" failures="0" errors="0" time="0.943">
  <testsuite name="..." errors="0" failures="0" skipped="0" timestamp="2022-02-05T13:33:33" time="0.252" tests="2">
    <testcase classname="..." name="..." time="0.059">
    </testcase>
    <testcase classname="..." name="..." time="0.009">
    </testcase>
  </testsuite>
</testsuites>

And a last try before I post this…

sonar.eslint.reportPaths="coverage/eslint.json"
sonar.flex.cobertura.reportPaths="coverage/cobertura-coverage.xml"
sonar.python.coverage.reportPaths="coverage/cobertura-coverage.xml"
sonar.php.coverage.reportPaths="coverage/clover.xml"

But flex, python and php are skipped because there is no related file in current project. :unamused:

Any ideas? Thanks in Advance!

Hi,

Property sonar.junit.reportPaths you are using is for Java and Kotlin. For JS/TS please check this doc Test Coverage & Execution | SonarQube Docs (Javascript and Typescript under Test execution analysis parameters). There you will find how to generate generic report, that’s how you provide tests info for JS/TS