gpt4 book ai didi

c# - 如何在我的 C# SonarQube 项目中包含测试覆盖率报告?

转载 作者:行者123 更新时间:2023-11-30 21:55:02 40 4
gpt4 key购买 nike

我目前有一个构建文件,可以在我的 SonarQube 服务器上生成基本分析报告。

MSBuild.SonarQube.Runner.exe begin /k:"mykey" /n:"myname" /v:"1.0.0"msbuild ... # build production codeMSBuild.SonarQube.Runner.exe endmsbuild ... # build test codeOpenCover ... # run test code and generate a (non-SonarQube) coverage report

到目前为止一切顺利。现在我想添加测试覆盖率报告。这就是我被困的地方。如何在我的 C# SonarQube 项目中包含测试覆盖率报告?

我尝试了两种方法来获取测试覆盖率报告,但都没有达到预期的效果:

  1. 运行两个单独的 MSBuild.SonarQube.Runner.exe session ,一个用于分析生产代码,另一个用于处理测试覆盖率报告;使用这种方法,我看不到错误,看不到基本分析,但看不到测试覆盖率报告:

    MSBuild.SonarQube.Runner.exe begin /k:"mykey" /n:"myname" /v:"1.0.0"msbuild ... # build production codeMSBuild.SonarQube.Runner.exe endMSBuild.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 codeOpenCover ... # run test code and generate a (non-SonarQube) coverage reportMSBuild.SonarQube.Runner.exe end
  2. 扩展原始 MSBuild.SonarQube.Runner.exe session 以包含与测试相关的构建代码;通过这种方法,我没有看到任何错误,但也看到了NO 报告:

    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 codemsbuild ... # build test codeOpenCover ... # run test code and generate a (non-SonarQube) coverage reportMSBuild.SonarQube.Runner.exe end

技术背景

  • SonarQube 5.1.2
  • C# 插件 5.2
  • MSBuild.SonarQube.Runner 1.0.1
  • NUnit.Runners.Net45.x64 2.6.3
  • OpenCover 4.5.3207

我的背景

其他背景

  • 我使用两个单独的 .csproj 文件将我的生产代码和测试代码分开在两个单独的 FS 树中。
  • 我通过两种方式将我的测试项目(其中有一个 MyTests.csproj 项目文件)标识为 SonarQube 的测试项目:

    1. 我将 sonar.cs.msbuild.testProjectPattern 设置为 [^\\]*Test[^\\]*$在 SonarQube 服务器上和
    2. 我添加 <SonarQubeTestProject>true</SonarQubeTestProject>到 MyTests.csproj 中的无条件 PropertyGroup。

最佳答案

第一种方法——运行 MSBuild.SonarQube.Runner.exe 两次,一次围绕构建,一次围绕测试——有效;第二种方法没有。

此处的关键是为 MSBuild.SonarQube.Runner.exe 提供测试报告 XML 文件的正确路径。我为它提供了不正确的路径,但这是行不通的。

关于c# - 如何在我的 C# SonarQube 项目中包含测试覆盖率报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32641263/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com