Search code examples
javascriptangularunit-testingsonarqubekarma-jasmine

Import Angular unit test report into Sonarqube


Context

In an Angular5 project using karma and jasmine for unit testing, I am generating this report file for my unit tests using karma-sonarqube-unit-reporter.

<testExecutions version="1">
  <file path="src/app/app.component.spec.ts">
    <testCase name="app/app.component.spec.ts should create the app" duration="314"/>
    <testCase name="app/app.component.spec.ts should have as title 'Projet de test Angular5'" duration="104"/>
    <testCase name="src/app/app.component.spec.ts should render title in a h1 tag" duration="114"/>
  </file>
  <file path="src/app/client-add/client-add.component.spec.ts">
    <testCase name="client-add/client-add.component.spec.ts should create" duration="107"/>
  </file>
  <file path="app/client.service.spec">
    <testCase name="app/client.service.spec #getClients should return an Observable&lt;Client[]>" duration="38"/>
  </file>
  <file path="src/app/message.service">
    <testCase name="app/message.service should be created" duration="35"/>
  </file>
</testExecutions>

But when I import it into Sonarqube (v6.7) (via Jenkins), I get the following

INFO: Sensor Generic Test Executions Report
WARN: Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.
INFO: Parsing C:\Users\adminpp\.jenkins\workspace\ELIS JustElis Beta WEB\reports\ut_report.xml
INFO: Imported test execution data for 0 files
INFO: Test execution data ignored for 4 unknown files, including:
src/app/app.component.spec.ts
src/app/client-add/client-add.component.spec.ts
src/app/client.service.spec
src/app/message.service
INFO: Sensor Generic Test Executions Report (done) | time=110ms

Here are my sonar properties for excluding and including sources and test codes.

sonar.sourceEncoding=UTF-8
sonar.sources=.
sonar.exclusions=**/node_modules/** 
sonar.test.inclusions = **/*.spec.ts
sonar.import_unkown_files=true
sonar.typescript.lcov.reportPaths=coverage/lcov.info
sonar.testExecutionReportPaths=reports/ut_report.xml

I checked and I have my *.spec.ts files where they are supposed to be.

Questions

Why Sonarqube doesn't find my files?

Have I missed a property or an important step?

(Is this property sonar.test.inclusions = **/*.spec.ts important?)


Solution

  • can you try to add property sonar.tests=. (value set to current directory) – Tibor Blenessy

    Adding this property in the sonar config worked for me.

    I got an error when I had the property sonar.tests set but not sonar.test.inclusions though but with the two, everything works fine.