I want to integrate Sonar integration into my .netcore 3.2
project.
I did it but test coverage was not shown in Sonar.
My docker sonar integration looks like this:
# install nodejs
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash - && apt-get install -y nodejs autoconf libtool nasm
ENV SolutionName MyProject
# reviewing this choice
ENV SONAR_SCANNER_MSBUILD_VERSION 4.8.0.12008
ARG branchName
RUN wget https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/$SONAR_SCANNER_MSBUILD_VERSION/sonar-scanner-msbuild-$SONAR_SCANNER_MSBUILD_VERSION-netcoreapp3.0.zip
RUN apt-get update && apt-get install -yy unzip
RUN unzip sonar-scanner-msbuild-$SONAR_SCANNER_MSBUILD_VERSION-netcoreapp3.0.zip -d /sonar-scanner
# Install Sonar Scanner
RUN rm sonar-scanner-msbuild-$SONAR_SCANNER_MSBUILD_VERSION-netcoreapp3.0.zip
RUN chmod +x -R /sonar-scanner
# Sonar scanner start
RUN dotnet /sonar-scanner/SonarScanner.MSBuild.dll begin /d:sonar.host.url=http://sonar.mycompany.com /d:sonar.login=111111/k:$SolutionName:"$branchName" /n:$SolutionName:"$branchName" /v:1 /d:sonar.cs.opencover.reportsPaths="/app/tests/MyProject.Tests/coverage.opencover.xml"
RUN dotnet test ./tests/CustomerServices.Tests/MyProject.Tests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
RUN dotnet publish ./src/MyProject.Api/MyProject.Api.csproj -o /publish
RUN dotnet /sonar-scanner/SonarScanner.MSBuild.dll end /d:sonar.login=111111
# Sonar scanner end
This integration shows bugs, code smells and quality gates but does not show coverage.
I also install coverlet.msbuild on my test project for test coverage but there is still no test coverage on my Sonar screen.
My Jenkins build like this.
Test Run Successful.
Total tests: 684
Passed: 684
Total time: 9.9564 Seconds
Calculating coverage result...
Generating report '/workdir/tests/MyProject.Tests/coverage.opencover.xml'
+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+
+---------+-----------+-----------+-----------+
| | Line | Branch | Method |
+---------+-----------+-----------+-----------+
| Total | 100% | 100% | 100% |
+---------+-----------+-----------+-----------+
| Average | Infinity% | Infinity% | Infinity% |
+---------+-----------+-----------+-----------+
How can I integrate Sonar for test coverage?