Search code examples
angularunit-testingsonarqubeangular-jest

Is there a way to bring number of unit tests under coverage in Sonarqube report for Angular-Jest project?


I have run sonar for Angular-Jest project and got the unit test coverage but am not getting number of unit tests.

My Sonar properties,(sonarqube version - 7.7)

sonar.host.url=http://localhost:9000
sonar.login=admin
sonar.password=admin
sonar.projectKey=my-app
sonar.projectName=my-app
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.exclusions=**/node_modules/**
sonar.tests=src
sonar.test.inclusions=**/*.spec.ts
sonar.typescript.lcov.reportPaths=coverage/my-app/lcov.info
sonar.scm.disabled=true
sonar.path.temp=C:\Sonar\sonarqube-7.7\temp

enter image description here

Is there any way to bring number of unit tests under coverage heading?

Thanks in advance!


Solution

  • After many trial and error, finally got the no.of unit tests in sonar report.

    Added sonar-scanner using the below command,

    npm install sonar-scanner --save-dev
    

    Then in package.json file add the following lines in scripts,

    "scripts": {
        "sonar": "sonar-scanner",
        "sonar-scanner": "node_modules/sonar-scanner/bin/sonar-scanner.bat"
      }
    

    In sonar-project.properties file, add the below line

    sonar.testExecutionReportPaths=test-report.xml
    

    Finally run sonar using StartSonar.bat and run

    npm run sonar
    

    And when we run https:localhost:9000/projects, we can find no.of unit tests under coverage part.

    enter image description here

    Reference links : https://medium.com/@learning.bikash/angular-code-coverage-with-sonarqube-d2283442080b

    https://medium.com/beingcoders/setup-sonarqube-with-angular-project-in-6-minutes-57a87b3ca8c4