Number of unit tests: 0 with 75% coverage

Hello Sonar community,

I have a C# project running on the Azure DevOps pipeline with integration with SonarQube. I’m using the classic mode of the pipeline with tasks without YML and configuring SonarQube in the “Prepare Analysis Configuration” task.

The test coverage is working correctly, but the number of unit tests is always showing zero, even though the project has several tests.

How can I fix this?

Below is how I am inserting the Sonar properties:

sonar.coverage.exclusions=folderX
sonar.cs.opencover.reportsPaths=coverage.opencover.xml
sonar.cs.nunit.reportsPaths=coverage.opencover.xml
sonar.tests.inclusions=src/project.Test/
sonar.visualstudio.solution=src/project.sln
sonar.language=cs

Hi,

Welcome to the community!

SonarQube won’t count your tests for you. That’s what the Nunit report is for. I see you’ve provided that parameter, but you’re pointing it to an OpenCover report? I’m fairly certain that if you look at your analysis logs, you’ll find that the attempt to read that report as an NUnit report is failing.

 
Ann

Hello, thank you for the response.

So, for example, if I set up Nunit, will the Sonarqube counter display the number of unit tests?

How do I properly configure the Nunit report?

I’m running tests in an Azure DevOps task using the command line like this:

dotnet test project.Test.csproj --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --settings $(Common.TestResultsDirectory)/CodeCoverage.runsettings --collect:“XPlat Code Coverage”

Before running, I create an XML file.

Am I doing it wrong?

Hi,

Sorry, but configuring NUnit is beyond the scope of this community.

 
Ann