SonarQube on Azure DevOps ignores test execution data for all files

Hi,

I’m trying to add SonarQube analysis to an Azure Devops pipeline on an Angular project.

Which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension):

  • SonarQube Developer Edition Version 8.1 (build 31237)
  • SonarQube Scanner 4.2.0.1873

What are you trying to achieve

I’m trying to analyze an Angular project from an Azure DevOps pipeline and publish the report to a SonarQube server.

What have you tried so far to achieve this

So far, the general analysis has worked (bugs, code smells, Quality Gate, etc.), however it seems unable to measure the code coverage.

This are the settings on the ‘Prepare Analysis Configuration’ step:

sonar.sources=src
sonar.exclusions=src/**/*.spec.ts,src/testing/**/*,src/assets/**/*
sonar.test=src
soanr.test.inclusions=src/**/*.spec.ts

sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.testExecutionReportPaths=coverage/sonar-test-reporter.xml

And this are what I assume to be the relevant parts of the Code Analysis log:

[...]
INFO: Found 1 tsconfig.json file(s): [C:\CI\4\_work\1140\s\tsconfig.json]
INFO: 370 source files to be analyzed
INFO: Analyzing 370 files using tsconfig: C:\CI\4\_work\1140\s\tsconfig.json
INFO: 0/370 files analyzed, current file: src/app/common/enums/window-type.ts
INFO: 0/370 files analyzed, current file: src/app/common/enums/window-type.ts
INFO: 153/370 files analyzed, current file: src/app/services/favorites/favorites.service.ts
INFO: 370/370 source files have been analyzed
INFO: Sensor TypeScript analysis [javascript] (done) | time=73072ms
INFO: Sensor Generic Test Executions Report
INFO: Parsing C:\CI\4\_work\1140\s\coverage\sonar-test-reporter.xml
INFO: Imported test execution data for 0 files
INFO: Test execution data ignored for 164 unknown files, including:
src/app/components/fragment-definition/create-edit-fragment/create-edit-fragment.component.spec.ts
src/app/components/navigation-bar/import-button/import-button.component.spec.ts
src/app/components/document-config/document-config.component.spec.ts
src/app/components/merge/merge.component.spec.ts
src/app/components/structure/structure.component.spec.ts
INFO: Sensor Generic Test Executions Report (done) | time=63ms
[...]

It looks that it’s unable to match the path in the report file to the actual file.

I’m also processing the report file changing the paths from abosulte to relative (e.g.: C:\CI\[...]\src\[...] to src/[...]) because the absolute ones didn’t work either.

I’ve also tried removing the sonar.exclusions setting, but the result has been the same.

What am I missing?

Thanks!

Hi @estranyg and welcome to the community !

sonar.test expects a pattern where your test file are, not the source meant to be covered. That’s probably something you need to look at for your issue.

Let us know.
Thanks
Mickaël

Hi,

I ended up removing all the settings everything on the ‘Prepare Analysis Configuration’ step and applying them in “Analysis Scope” on the SonarQube UI and everything worked correctly.

Thanks!

1 Like

Hi,

I have exactly the same issue ; but I do not understand the solution provided : where is located that ‘Prepare Analysis Configuration’ stuff ?
I have parameterized nothing in the GUI, all the configuration is in the sonar-project.properties :

sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.testExecutionReportPaths=coverage/test-report.xml
sonar.exclusions=**/__tests__/**,**/stories/**
sonar.test.inclusions=**/*.spec.js
sonar.eslint.reportPaths=coverage/eslint-report.json

Note that everything is working as expected : analysis and eslint report too !

Many thanks.
Philippe.

A post was split to a new topic: Code coverage not appearing in SonarCloud