声纳C#ecosystem:如何配置IT测试覆盖率

时间:2013-05-08 08:35:40

标签: c# plugins integration-testing sonarqube

我们有一个.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执行集成测试作为“单元测试”并且代码覆盖率有效。任何提示?

1 个答案:

答案 0 :(得分: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"