Azure DevOps code coverage issue

I’m using :
SonarQube Version 6.7.5 (build 38563)
Sonar Scanner plugin in AzureDevOps
In general, all build process in going in Azure DevOps pipelines in on-premise agents

Can’t collect CodeCoverage report after unit tests.
If I’m using VisualStudio Tests assembly with enabled CodeCoverage tests run failed without any reason.
I’ve installed coverlet.msbuild package in my solution and run MSBuild with options :
/p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=$(Build.SourcesDirectory)\CodeCoverage\coverage.opencover.xml

After that got only one message in the Run Code Analysis task :
15:35:34.08 Attempting to locate the CodeCoverage.exe tool…
15:35:34.096 Attempting to locate the CodeCoverage.exe tool using setup configuration…
15:35:34.112 Code coverage command line tool: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe
15:35:34.112 Fetching code coverage report information from TFS…
15:35:34.112 Attempting to locate a test results (.trx) file…
15:35:35.002 Looking for TRX files in: D:\vstsagent_gafvso1_work\8\TestResults
15:35:35.002 No test results files found
15:35:35.815 Did not find any binary coverage files in the expected location.
15:35:35.815 Falling back on locating coverage files in the agent temp directory.
15:35:35.815 Searching for coverage files in D:\vstsagent_gafvso1_work_temp
15:35:35.815 No coverage files found in the agent temp directory.

Maybe someone could help me with this issue, I’me ready to share more information when it will be needed.

Could you share your yaml pipeline? My first instinct is that the test results are being created just not in the location that Sonar expects.

Could you try adding the following to extraProperties:

      sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx

pool:
name: GAFComServices1
demands:

  • msbuild
  • visualstudio
  • vstest
  • java

variables:
BuildPlatform: ‘any cpu’

steps:

  • task: SonarSource.sonarqube.15B84CA1-B62F-4A2A-A403-89B77A063157.SonarQubePrepare@4
    displayName: ‘Prepare analysis on SonarQube’
    inputs:
    SonarQube: ‘GAF SonarQube’
    projectKey: GAFComSitecore
    projectName: ‘GAF.GAFComSitecore.SVC (DEV)’
    projectVersion: '(Build.BuildNumber)' extraProperties: | sonar.exclusions = **/*.zip, **/*.bin, **/bld/**/*, **/*.xml, **/jQuery*/**, **/*.Tests/**, **/*.item, **/Assets/**, **/assets/**, **/*.js sonar.inclusions= **/*.css, **/*.less, **/*.scss, **/*.cs, **/*.html ,**/*.xhtml, **/*.cshtml, **/*.aspx , **/*.ascx, **/*.*html, **/*.shtm sonar.verbose=true system.debug=true sonar.visualstudio.enable=true sonar.cs.vstest.reportsPaths=(Agent.TempDirectory)/*.trx

    #sonar.cs.opencover.reportsPaths=(Build.SourcesDirectory)\CodeCoverage\coverage.opencover.xml #sonar.coverageReportPaths=(System.DefaultWorkingDirectory)\TestResults\Coverage\Reports
    #sonar.cs.opencover.reportsPaths=(System.DefaultWorkingDirectory)\opencover.xml #sonar.cs.vscoveragexml.reportsPaths=(Agent.TempDirectory)\TestResults**.coverage
    #sonar.cs.opencover.reportsPaths=(System.DefaultWorkingDirectory)/opencover.xml #sonar.coverageReportPaths="(Agent.BuildDirectory)\TestResults\coverage.opencover.xml"
    #sonar.cs.opencover.reportPaths=D:\vstsagent_gafvso1_work_temp*coverage.xml
    #sonar.cs.vstest.reportsPaths=D:\vstsagent_gafvso1_work_temp\TestResults*.trx
    #sonar.cs.vscoveragexml.reportsPaths=**/
    .coveragexml

  • task: NuGetCommand@2
    displayName: ‘NuGet restore GAF DXP/GAF DXP.sln’
    inputs:
    restoreSolution: ‘GAF DXP/GAF DXP.sln’
    feedsToUse: config
    nugetConfigPath: ‘GAF DXP/NuGet.config’
    noCache: true

  • task: VSBuild@1
    displayName: ‘Build solution GAF DXP/GAF DXP.sln’
    inputs:
    solution: ‘GAF DXP/GAF DXP.sln’
    vsVersion: 15.0
    msbuildArgs: ‘/p:IsDesktopBuild=false’
    configuration: ‘$(BuildConfiguration)’
    clean: true
    msbuildArchitecture: x64

  • task: NuGetCommand@2
    displayName: ‘NuGet restore GAF DXP/GAF DXP Helix.sln’
    inputs:
    restoreSolution: ‘GAF DXP/GAF DXP Helix.sln’
    feedsToUse: config
    nugetConfigPath: ‘GAF DXP/NuGet.config’
    noCache: true

  • task: VSBuild@1
    displayName: ‘Build solution GAF DXP/GAF DXP Helix.sln’
    inputs:
    solution: ‘GAF DXP/GAF DXP Helix.sln’
    vsVersion: 15.0
    msbuildArgs: ‘/p:IsDesktopBuild=false /p:OutDir=(System.DefaultWorkingDirectory)\bin /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=(Build.SourcesDirectory)\CodeCoverage\coverage.opencover.xml’
    configuration: ‘$(BuildConfiguration)’
    clean: true
    msbuildArchitecture: x64

  • powershell: ‘New-Item -ItemType “directory” -Path “$(Build.SourcesDirectory)\CodeCoverage”’
    displayName: ‘Create Test Result Dir’
    continueOnError: true

  • powershell: ‘Copy-Item -Path ‘’(System.DefaultWorkingDirectory)\GAF DXP\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll'' -Destination ''(System.DefaultWorkingDirectory)\bin’’’
    errorActionPreference: continue
    displayName: ‘Copy dll’
    continueOnError: true

  • task: VSTest@2
    displayName: ‘Run Unit Test Assemblies’
    inputs:
    testAssemblyVer2: |
    *.Tests.Unit.dll
    !
    *TestAdapter.dll
    !**\obj**
    vsTestVersion: 15.0
    pathtoCustomTestAdapters: ‘(System.DefaultWorkingDirectory)\GAF DXP\packages\xunit.runner.visualstudio.2.4.0\build\_common' runInParallel: false runTestsInIsolation: true codeCoverageEnabled: false platform: '(BuildPlatform)’
    configuration: ‘$(BuildConfiguration)’
    diagnosticsEnabled: true
    rerunFailedTests: false
    continueOnError: true

  • powershell: ‘Get-ChildItem “$(Build.SourcesDirectory)\CodeCoverage”’
    displayName: ‘Debug Test Dir’
    continueOnError: true

  • task: SonarSource.sonarqube.6D01813A-9589-4B15-8491-8164AEB38055.SonarQubeAnalyze@4
    displayName: ‘Run Code Analysis’
    continueOnError: true

  • task: SonarSource.sonarqube.291ed61f-1ee4-45d3-b1b0-bf822d9095ef.SonarQubePublish@4
    displayName: ‘Publish Quality Gate Result’
    continueOnError: true

Shared with you my pipeline above