sonar c#生态系统:如何配置IT测试覆盖率

本文关键字:配置 IT 测试 覆盖率 测试覆盖 生态系统 何配置 sonar | 更新日期: 2023-09-27 18:12:41

我们有一个。net c#解决方案,其中包含一些首次集成测试,但没有单元测试。我要如何配置声纳项目。属性以使测试执行和代码覆盖工作?当使用:

sonar.dotnet.visualstudio.testProjectPattern=*.Tests;*.Test
sonar.dotnet.visualstudio.itProjectPattern=*.IntegrationTest
sonar.opencover.installDirectory=C:/Program Files/OpenCover
sonar.gallio.coverage.tool=OpenCover
sonar.gallio.runner=IsolatedProcess
sonar.gallio.it.mode=active

声纳说:

14:42:55.813 INFO  p.d.a.m.ModelFactory - The project 'foo.IntegrationTest' has been  qualified as a test project.
14:42:55.844 INFO  p.d.a.m.ModelFactory - The project 'bar.IntegrationTest' has been qualified as a test project.
...
Gallio won't execute as there are no test projects

当更改测试模式时:

sonar.dotnet.visualstudio.testProjectPattern=*.IntegrationTest
#sonar.dotnet.visualstudio.itProjectPattern=*.IntegrationTest

gallio将集成测试作为"单元测试"执行,并且代码覆盖工作。有提示吗?

sonar c#生态系统:如何配置IT测试覆盖率

我将此用于代码覆盖率生成。例如项目是Test/Test.csproj

cd ./Test
nuget install Microsoft.CodeCoverage -OutputDirectory ./packages
嵌套目录中的./packages中的

将是CodeCoverage.exe

dotnet test --no-build logger trx --collect "CodeCoverage" /p:Debug=full -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.CoverageFileName="test.coverage"

在嵌套目录的TestResults中会有test。覆盖文件。将其转换为coveragexml

CodeCoverage.exe analyze /output:test.coveragexml test.coverage

然后在sonarscanner

中使用
./SonarScannerMsbuild.exe /d:"sonar.cs.vstest.reportsPaths=./**/*.trx" /d:"sonar.cs.vscoveragexml.reportsPaths=./**/*coveragexml"