I currently have a build file that results in basic-analysis report on my SonarQube server.
MSBuild.SonarQube.Runner.exe begin /k:"mykey" /n:"myname" /v:"1.0.0" msbuild ... # build production code MSBuild.SonarQube.Runner.exe end msbuild ... # build test code OpenCover ... # run test code and generate a (non-SonarQube) coverage report
So far so good. Now I would like to add test-coverage reports to the mix. This is where I am stuck. How can I include test-coverage reports in my C# SonarQube project?
I have tried two ways to get test-coverage reports, but neither have the desired effect:
run two separate MSBuild.SonarQube.Runner.exe sessions, one for analyzing the production code and another for handling the test-coverage report; with this approach I see no errors, see basic analysis, but see no test-coverage reports:
MSBuild.SonarQube.Runner.exe begin /k:"mykey" /n:"myname" /v:"1.0.0" msbuild ... # build production code MSBuild.SonarQube.Runner.exe end MSBuild.SonarQube.Runner.exe begin /k:"mykey" /n:"myname" /v:"1.0.0" /d:sonar.cs.opencover.reportsPaths="opencover.xml" /d:sonar.cs.nunit.reportsPaths="nunit.xml" msbuild ... # build test code OpenCover ... # run test code and generate a (non-SonarQube) coverage report MSBuild.SonarQube.Runner.exe end
expand the original MSBuild.SonarQube.Runner.exe session to include the test-related build code; with this approach I see no errors, but also see NO reports:
MSBuild.SonarQube.Runner.exe begin /k:"mykey" /n:"myname" /v:"1.0.0" /d:sonar.cs.opencover.reportsPaths="opencover.xml" /d:sonar.cs.nunit.reportsPaths="nunit.xml" msbuild ... # build production code msbuild ... # build test code OpenCover ... # run test code and generate a (non-SonarQube) coverage report MSBuild.SonarQube.Runner.exe end
Technical background
- SonarQube 5.1.2
- C# Plugin 5.2
- MSBuild.SonarQube.Runner 1.0.1
- NUnit.Runners.Net45.x64 2.6.3
- OpenCover 4.5.3207
My background
- I am experienced in Java and Java with SonarQube but new to C# and C# with SonarQube.
- I have read
Other background
- I separate my production code and test code in two separate FS trees with two separate .csproj files.
I identify my test project, which has a MyTests.csproj project file, to SonarQube as a test project in two ways:
- I set sonar.cs.msbuild.testProjectPattern to
[^\\]*Test[^\\]*$
on the SonarQube server and - I add
<SonarQubeTestProject>true</SonarQubeTestProject>
to the unconditional PropertyGroup in MyTests.csproj.
- I set sonar.cs.msbuild.testProjectPattern to