我想将Sonar集成到我的.netcore 3.2
项目中。
我做了,但测试覆盖率没有显示在声纳。
我的Docker声纳集成看起来像这样:
# 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
这种集成显示了bug、代码气味和质量门,但没有显示覆盖率。
我还在我的测试项目上安装了coverlet.msbuild以获得测试覆盖率,但是在我的Sonar屏幕上仍然没有测试覆盖率。
Jenkins就是这样的。
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% |
+---------+-----------+-----------+-----------+
如何集成Sonar以实现测试覆盖?
1条答案
按热度按时间enxuqcxy1#
您需要在sonar scanner开始命令之前传递dotnet test命令,因为使用dotnet test命令,我们将使用/p:CollectCoverage=true /p:CoverletOutputFormat=opencover生成带有coverage.opencover.xml的报告
请随时更新reuslt。谢谢