- 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

Hi,

Same issue here. We cannot use ‘sonar.junit.reportPaths’ for TypeScript / jest. We are using LTS 9.9

We are exporting format to XML/JUnit in order to display them on our CI (Jenkins)

backstage-cli repo test --reporters=jest-junit

I don’t see any reporter for jest an SonarQube generic format
(Generic test data)

Why cannot we use a well used JUnit format ? Why limiting it only for Java ?

Only passing the sonar.javascript.lcov.reportPaths: coverage/lcov.info don’t display the number of test. Only coverage

lcov_sonar

Thanks!

This is unfortunately still an issue - SonarQube ignores junit results if the test file isn’t not Java and xunit results if the test file isn’t Python - even if the path matches exactly.

10:14:37.349 DEBUG: Trying to find a SonarQube resource for test case 'e2e/sanity/actions/xxx.spec.ts'
10:14:37.349 DEBUG: Using the key 'e2e/sanity/actions/xxx/spec/ts.py' to lookup the resource in SonarQube
10:14:37.363 DEBUG: Using the key 'e2e/sanity/actions/xxx/spec.py' to lookup the resource in SonarQube
10:14:37.377 WARN: The resource for 'e2e/sanity/actions/xxx.spec.ts' is not found, drilling down to the details of this test won't be possible

Unfortunately there don’t seem to be any tools available to readily convert JUnit XMLs to the generic test report format and only a few testing frameworks have generic test format reporters available for them.