Version information:
Sonar Scanner 4.0.2
Dotnet SDK 2.1.401
Dotnet Core 2.0
NUnit 3
Bamboo
what are you trying to achieve: Test coverage for all projects with corresponding unit tests
what have you tried so far to achieve this: So far, we have tried using various cli arguments, as well as different configurations in the csproj files
Our project is structured like this:
--src
--main
--ProjectA
--ProjectB
--ProjectC
--test
--ProjectATests
--ProjectBTests
--ProjectCTests
abc.sln
our test csproj files have the following in the PropertyGroup header
<SonarQubeTestProject>true</SonarQubeTestProject>
Through bamboo we are running with the following arguments with the Sonar Begin task
/d:sonar.cs.opencover.reportsPaths=“test//coverage.opencover.xml"
/d:sonar.verbose=“true”
/d:sonar.cs.vstest.reportsPaths="test//TestResults/test-results.trx”
We are using
dotnet test -c Release -l "trx;LogFileName=test-results.trx" $proj /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutputDirectory=TestResults
to run our tests
We have tried to structure our pipeline to do this as well
https://stackoverflow.com/questions/32641263/how-can-i-include-test-coverage-reports-in-my-c-sharp-sonarqube-project
but there was no success there.
The problem:
We are trying to get our coverage to be reported accurately across the entire project. Currently it appears to be getting coverage for ProjectB, for one or two classes in Project A and then not picking up any tests at all in Project C. With adding in the vstest trx files, we can see total number of unit tests. But we cannot see the individual test names or any other information about the tests. Without that argument and only using the opencover argument, we can only see coverage with no information about the unit tests. That doesn’t make any change to the coverage.
If it helps, our pipeline goes like this:
dotnet build-server shutdown
source control checkout -- clean
sonar scanner for msbuild begin
dotnet restore
dotnet build
dotnet test
mstest parser
sonar end
We have also tried with NUnit parser between mstest parser and sonar end, but could not find a way to get sonar to pick up the output
Any help would be great!