Sonarqube Cannot Show Sum of .Net Core Unit Tests - NUnit And Vue.Js Unit Tests - Jest

I have an issue about Sonarqube Count of Unit Test corretly. My project’s backend is .net core web api project and frontend is VueJs project. I wrote unit test both of them. But I can not see total unit tests number after Sonarqube scanner. I run Sonarqube Scanner on Azure Pipelines.

My sonarqube.properties is:

sonar.verbose=true
sonar.cs.vstest.reportsPaths=$(System.DefaultWorkingDirectory)\**\*.trx
sonar.cs.opencover.reportsPaths=$(System.DefaultWorkingDirectory)\**\*.opencover.xml
sonar.typescript.tsconfigPath=<absolute-path>/tsconfig.json
sonar.javascript.lcov.reportPaths=<absolute-path>/lcov.info
sonar.testExecutionReportPaths=<absolute-path>/test-sonar-reporter.xml
sonar.sources=<absolute-path>/src
sonar.tests=<absolute-path>/tests
sonar.test.inclusions=$(System.DefaultWorkingDirectory)/**/*.spec.ts

By the way, I have got 15 .net core unit tests and 1 vuejs unit test.

My package.json file is:

"devDependencies": {
    ...
    "@types/jest": "26.0.14",
    "jest-junit": "^12.0.0",
    "jest-sonar-reporter": "^2.0.0",
    "@vue/test-utils": "1.1.0",
    "@vue/cli-plugin-unit-jest": "4.5.7",
},
"jest-junit": {
    "outputDirectory": "./coverage/test-results",
    "outputName": "test-reports-junit.xml"
},
"jestSonar": {
    "reportPath": "./coverage/test-results",
    "reportFile": "test-sonar-reporter.xml",
    "indent":  4
}

And jest.config.js is

module.exports = {
  preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
  collectCoverage: true,
  collectCoverageFrom: [
    'src/**/*.{ts,vue}',
    '!src/main.ts', // No need to cover bootstrap file
  ],
  coverageReporters: ["json", "lcov", "text", "clover", "cobertura"],
  reporters: [ "default", "jest-junit" ],
  testResultsProcessor: "jest-sonar-reporter"
}

After Sonarqube scanner, Code coverages are shown correctly.
And then, I expect 16 Unit tests but written 15 Unit tests, can you help me about this.

Unit Tests Image

Anybody help me?

Hi @hakanaltindis! Welcome to SonarSource Community!

Can you list the exact commands you ran and provide the debug logs of your SonarScanner analysis?

I scanned my code on Azure Pipelines. And I got debug log file, but it is too big. Which part of the log will you want to see exactly?

Please attach the logs associated with the SonarScanner. You can zip it up or post it gist.github.com if it’s easier.

My log file in this repository. I hope it is helpful for you.

Hi @hakanaltindis,

Apologies for the delay. I’m reviewing your logs still.

Can you help answer some questions?

  1. What version of SonarQube are you using? Which edition (developer, community, enterprise)?
  2. If you are not on 7.9 or 8.5.1, please upgrade your SonarQube to those versions and upgrade all the plugins you require for the analysis of this project.

If you do upgrade, please rerun your analysis in debug mode and please show the logs for it.

Joe

EDIT:

Can you try moving the Vue.js files into a new project and verify that the lcov.info file is imported correctly for that 1 test? I would scan it as a new project.

Also, I would also test that your .NET core project (without the Vue.js test) still scans properly and shows 15 unit tests. Can you let me know the results of this test?

In the meantime, I’ll continue to check your logs for anything unusual.

First of all, don’t be sorry and thanks for your help. :slight_smile:

  1. Our Sonarqube is community edition.
  2. Sonarqube version is 8.5.0.37579. And I will upgrade 8.5.1, then run analysis again.

I will try your other suggestions and update you.

1 Like

Hi again,

Sorry about late answer. Our Sonarqube admin was busy. So we upgraded sonarqube 8.5.1 this morning. I scanned project again but result was not changed. I uploaded new sonar scanner log with sonar.log.level=debug, you can access with this link.

I tried your suggestions. I run sonar scanner for only .net core projects and the sonarqube show correct number of tests(15).
But I cant run sonar scanner for only vue project. “Run Code Analysis” step was failed. Error is The SonarScanner for MSBuild integration failed: SonarQube was unable to collect the required information about your projects

EDIT:

I found my issue. I could run sonar scanner for only vue project and then the result was shown correct number of test(1)

EDIT 2:
There is something on my mind. I chose Integrate with MSBuild for full scan in Prepare Analysis Configuration Step
image
Could this be wrong? What do you thing about that?

Hi @Joe

Can you find anything?

@hakanaltindis: Sorry for the late reply, I was on holiday. Do you have a way to reproduce this issue? Do you have a sample project that is both .NET and vue with unit tests in it? If you can replicate it in a small project and send to me, then this will help the investigation go quicker since I haven’t set up such a project before.

I’ll attempt to recreate the issue myself in the mean time with this template: https://github.com/based-ghost/aspnet-core-vue-fullstack-testing

Joe