2

I am using azure devops for running a test and trying to integrate sonarqube with it.The issue i am facing is that in the summary part of azure pipeline i am able to view code coverage as 22% but in the sonarqube console i am only able to view code coverage as '-'.There is a warning message that i am seeing when i run 'Run Code Analysis' task in pipeline. The warning message is WARN: The Code Coverage report doesn't contain any coverage data for the included files. [Please find the image to view the code coverage displayed in azure pipeline][1]

This is the yaml for dot test task

- task: DotNetCoreCLI@2
  displayName: 'dotnet test'
  inputs:
  command: test
  projects: '**/*Test*.csproj'
  arguments: '--configuration $(BuildConfiguration) --collect "Code coverage"  '
  workingDirectory: '$(System.DefaultWorkingDirectory)'

This is the yaml for copy files task that i am doing right after the dot test task
steps:
- task: CopyFiles@2
  displayName: 'Copy Files to: $(Common.TestResultsDirectory)'
  inputs:
    SourceFolder: '$(Agent.WorkFolder)\_temp'
    TargetFolder: '$(Common.TestResultsDirectory)'

Please find the yaml file for Prepare analysis on sonarqube task
displayName: 'Prepare analysis on SonarQube'
  inputs:
    SonarQube: 'CDA-Sonarqube'
    projectKey: Test
    projectName: Test
    extraProperties: sonar.cs.nunit.reportsPaths

Any help is appreciated.


  [1]: https://i.stack.imgur.com/HbZfW.png
Gokul Vijayan
  • 105
  • 1
  • 11

2 Answers2

0
WARN: The Code Coverage report doesn't contain any coverage data for the included files.

For troubleshooting hints, please refer to https://docs.sonarqube.org/x/CoBh , the .coverage file will be convert to coveragexml during sonarqube end analysis task

Run Unit Tests and Save Results in file "NUnitResults.xml"

packages\NUnit.ConsoleRunner.3.7.0\tools \ nunit3-console.exe --result=NUnitResults.xml "NUnitTestProject1\bin\Debug\NUnitTestProject1.dll"

or, for older NUnit 2

"%ProgramFiles(x86)%\NUnit 2.6.4\bin \nunit-console.exe /result=NUnitResults.xml "NUnitTestProject1\bin\Debug\NUnitTestProject1.dll"

Meanwhile,there is a workaround explained in the VSTS extension documentation in "Analysing a .NET solution": in the Additional Properties text area, add the following property:

sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml

You can also refer to these cases(case1 , case2) for details.

Here is a blog about configuring Code Coverage for Dotnet Core based applications using SonarQube and Azure DevOps .

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
0

By default the test result files are in temp folder, try to copy files through Copy File task, then the .coverage file will be analysis and generate coveragexml file.

- task: CopyFiles@2

  displayName: 'Copy Files to: $(build.sourcesdirectory)\TestResults'

  inputs:

    SourceFolder: '$(Agent.TempDirectory)'

    TargetFolder: '$(build.sourcesdirectory)\TestResults'

On the other hand, you can refer to this article to call CodeCoverage.exe: Configure Code Coverage for Dotnet Core 2.0 based applications using SonarQube and Azure DevOps

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53