Condition coverage across multiple tests

It’s been a while since I’ve been having coverage problems, exclusively in conditions to cover, I realized that when I have two test projects, and each one of them testing the same line but with different conditions, sonarqube is not “adding” these conditions at the end.

I would like to know more about it, is this something I’m doing wrong? is it a known debt? Is it a problem that has no solution?

currently I’m using Coverlet.Collector, XUnit and the following tasks in AzureDevops


  • task: DotNetCoreCLI@2
    displayName: ‘dotnet test’
    command: test
    projects: ‘$(ProjectPathTest)’
    arguments: ‘–configuration $(BuildConfiguration) --no-restore --collect:“XPlat Code Coverage”’
    publishTestResults: false


  • task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@5
    displayName: ‘ReportGenerator to sonar’
    reports: ‘$(Build.SourcesDirectory)/**/TestResults/*/coverage.cobertura.xml’
    targetdir: ‘$(Agent.BuildDirectory)/sonarqubecoverage’
    reporttypes: ‘HtmlInline_AzurePipelines;Cobertura;SonarQube’

There’s only small thing that you said here that seems like a clue to me. You refer to two different projects. They may be including the same code in a library, but if you’re running one scan in one project, and another scan in the other project, those two scans don’t have anything to do with each other, at least not with respect to the resulting coverage in the scan.

Thank for your help
I understand that they are different tests, but as they are the same repository in the same solution, is it not expected that the two will add up?

currently the coverages add up, however when it comes to coverage of conditions this does not happen

No. Two separate scans are two separate scans, and they are not “combined” in any way. It makes no difference if both of them are analyzing the same code, or different code.

Write your tests so that a single run of your tests gets all of the test coverage you require.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.