Don’t see Unit Tests count in sonarQube portal (Monorepo & Angular)

Hi Guys, We are not able to see unit test count for Angular application from sonarQube portal.

We are using sonarsource/sonar-scanner-cli image to execute execute sonarQube scans

SonarQube Properties :-

-Dsonar.projectKey="$service-name" \
-Dsonar.sources="folder/apps/$service/src/." \
-Dsonar.projectName="$service-name" \
-Dsonar.host.url=$(sonarqube-host) \
-Dsonar.projectVersion=$(VER) \
-Dsonar.javascript.lcov.reportPaths="sonarqube_reports/$service/lcov.info" \
-Dsonar.testExecutionReportPaths="sonarqube_reports/$service/sonarqube_report.xml" \
-Dsonar.login="$(sq-apitoken)" \
-Dsonar.branch.name=$(currentBranch) \
-Dsonar.tests="folder/apps/$service/src" \
-Dsonar.exclusions=**/*.css,**/*.html,**/node_modules/**,**/*.yaml,**/*.yml \
-Dsonar.test.inclusions=**/*.spec.ts \
-Dsonar.language=ts 

sonarqube_report.xml data:-

<testExecutions version="1">
  <file path="apps/service_name/src/app/remote-entry/service/service_name.component.spec.ts">
    <testCase name="Service function name() should http POST" duration="714"/>
  </file>
</testExecutions>

Logs:-

: Parsing /usr/src/sonarqube_reports/service_name/sonarqube_report.xml
INFO: Imported test execution data for 0 files
INFO: Test execution data ignored for 9 unknown files, including:
apps/service_name/src/app/remote-entry/service_name/ui/services/services.component.spec.ts
apps/service_name/src/app/remote-entry/service_name/data-access/service_name.service.spec.ts
apps/service_name/src/app/remote-entry/service_name/feature/sc-attributes/sc-attributes.component.spec.ts
apps/service_name/src/app/remote-entry/service_name/ui/hierarchy/hierarchy.component.spec.ts
apps/service_name/src/app/remote-entry/service_name/data-access/service_name.reducer.spec.ts
INFO: Sensor Generic Test Executions Report (done) | time=25ms
INFO: Sensor javabugs [dbd]
INFO: Reading IR files from: /usr/src/.scannerwork/ir/java
INFO: No IR files have been included for analysis.
INFO: Sensor javabugs [dbd] (done) | time=4ms
INFO: Sensor pythonbugs [dbd]
INFO: Reading IR files from: /usr/src/.scannerwork/ir/python
INFO: No IR files have been included for analysis.
INFO: Sensor pythonbugs [dbd] (done) | time=2ms
INFO: Sensor JavaSecuritySensor [security]
INFO: Reading type hierarchy from: /usr/src/.scannerwork/ucfg2/java
INFO: Read 0 type definitions 
INFO: Sensor JavaSecuritySensor [security] (done) | time=5ms
INFO: Sensor CSharpSecuritySensor [security]
INFO: Reading type hierarchy from: /usr/src/ucfg_cs2
INFO: Read 0 type definitions
INFO: No UCFGs have been included for analysis.
INFO: Sensor CSharpSecuritySensor [security] (done) | time=1ms
INFO: Sensor PhpSecuritySensor [security]
INFO: Reading type hierarchy from: /usr/src/.scannerwork/ucfg2/php
INFO: Read 0 type definitions
INFO: No UCFGs have been included for analysis.
INFO: Sensor PhpSecuritySensor [security] (done) | time=2ms
INFO: Sensor PythonSecuritySensor [security]
INFO: Reading type hierarchy from: /usr/src/.scannerwork/ucfg2/python
INFO: Read 0 type definitions
INFO: No UCFGs have been included for analysis.
INFO: Sensor PythonSecuritySensor [security] (done) | time=2ms
INFO: Sensor JsSecuritySensor [security]
INFO: Reading type hierarchy from: /usr/src/.scannerwork/ucfg2/js
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /usr/src/.scannerwork/ucfg2/js
INFO: 16:23:04.653456429 Building Runtime Type propagation graph
INFO: 16:23:04.682087732 Running Tarjan on 912 nodes
INFO: 16:23:04.690340225 Tarjan found 912 components
INFO: 16:23:04.698935047 Variable type analysis: done
INFO: : 16:23:04.653456429 Building Runtime Type propagation graph
INFO: 16:23:04.682087732 Running Tarjan on 912 nodes
INFO: 16:23:04.690340225 Tarjan found 912 components
INFO: 16:23:04.698935047 Variable type analysis: done
INFO: 16:23:04.701248241 Building Runtime Type propagation graph
INFO: 16:23:04.719633085 Running Tarjan on 912 nodes
INFO: 16:23:04.721181315 Tarjan found 912 components
INFO: 16:23:04.723547413 Variable type analysis: done
INFO: Analyzing 200 ucfgs to detect vulnerabilities.
INFO: Taint analysis starting. Entrypoints: 44
INFO: Running symbolic analysis for 'JS'
INFO: Taint analysis: done.
INFO: Sensor JsSecuritySensor [security] (done) | time=2017ms
INFO: ------------- Run sensors on project
INFO: Sensor Analysis Warnings import [csharp]
INFO: Sensor Analysis Warnings import [csharp] (done) | time=2ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=10ms
INFO: SCM Publisher SCM provider for this project is: git
INFO: SCM Publisher 57 source files to be analyzed
WARN: Shallow clone detected, no blame information will be provided. You can convert to non-shallow with 'git fetch --unshallow'.
INFO: SCM Publisher 0/57 source files have been analyzed (done) | time=10ms
WARN: Missing blame information for the following files:
WARN:   * jarvis/apps/service_name/src/app/remote-entry/service_name/feature/service_name-import/service_name-import.component.scss
WARN:   * jarvis/apps/service_name/src/test-setup.ts
WARN:   * jarvis/apps/service_name/src/app/constants/default-table-state.constant.ts
WARN:   * jarvis/apps/service_name/src/app/remote-entry/service_names/data-access/service_name.reducer.ts
WARN: This may lead to missing/broken features in SonarQube
INFO: CPD Executor 22 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 21 files
INFO: CPD Executor CPD calculation finished (done) | time=15ms
INFO: Load New Code definition
INFO: Load New Code definition (done) | time=305ms
INFO: Analysis report generated in 393ms, dir size=450.8 kB
INFO: Analysis report compressed in 124ms, zip size=233.4 kB
INFO: Analysis report uploaded in 514ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sq.devops.org.com/dashboard?id=si-web-mono-service_name&branch=feature
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at https://sq.devops.org.com/api/ce/task?id=AYqPWn-XBRFI0mERb5VS
INFO: Time spent writing ucfgs 146ms
INFO: Analysis total time: 50.550 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:24.221s
INFO: Final Memory: 77M/227M

image

1 Like

Hi,

Thanks for such a thorough initial post!

I see this in your log:

The files are “unknown” because the paths in the report don’t match the paths analysis is seeing. Your sonar.tests path is

but I don’t see folder at the start of the paths in the report, e.g.

Make those two things match up, and this should work.

On a side note, this parameter does nothing. You can remove it:

 
HTH,
Ann

1 Like

Hi Ann,

Thanks this solves the issue.

2 Likes