1

我们有一个 .NET C# 解决方案,其中包含一些首次集成测试,但没有单元测试。我必须如何配置 sonar-project.properties 才能使测试执行和代码覆盖率正常工作?使用时:

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 将集成测试作为“单元测试”执行,并且代码覆盖率有效。有什么提示吗?

4

1 回答 1

0

我正在使用它来生成代码覆盖率。例如项目是 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.coverage 文件。将其转换为coveragexml

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

然后在声纳扫描仪中使用它

./SonarScannerMsbuild.exe /d:"sonar.cs.vstest.reportsPaths=./**/*.trx" /d:"sonar.cs.vscoveragexml.reportsPaths=./**/*coveragexml"
于 2020-08-01T18:29:26.393 回答