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:
\nMSBuild.SonarQube.Runner.exe begin /k:"mykey" /n:"myname" /v:"1.0.0" \nmsbuild ... # build production code \nMSBuild.SonarQube.Runner.exe end \nMSBuild.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" \nmsbuild ... # build test code \nOpenCover ... # run test code and generate a (non-SonarQube) coverage report \nMSBuild.SonarQube.Runner.exe end \n
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:
\nMSBuild.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" \nmsbuild ... # build production code \nmsbuild ... # build test code \nOpenCover ... # run test code and generate a (non-SonarQube) coverage report \nMSBuild.SonarQube.Runner.exe end \n
I identify my test project, which has a MyTests.csproj project file, to SonarQube as a test project in two ways:
[^\\\\]*Test[^\\\\]*$
on the SonarQube server and <SonarQubeTestProject>true</SonarQubeTestProject>
to the unconditional PropertyGroup in MyTests.csproj. The first approach--run MSBuild.SonarQube.Runner.exe twice, once around the build and once around the testing--works; the second approach does not.
The key here is to provide MSBuild.SonarQube.Runner.exe with correct paths to the test-report XML files. I wast providing it with incorrect paths, and that doesn't work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.