我正在尝试为C#项目设置单元测试和代码覆盖率。我使用声纳转轮作为分析仪,Gallio 3.4.14 OpenCover4.5.1 这是sonar-project.properties文件:
sonar.projectKey=Foo
sonar.projectName=Foo-SonarQube Runner
sonar.projectVersion=1.0
# Path to the source directories (required)
sonar.sources=.
sonar.language=cs
sonar.sourceEncoding=UTF-8
sonar.dotnet.visualstudio.solution.file=Foo.sln
sonar.silverlight.4.mscorlib.location=C:\Program Files (x86)\Reference Assemblies
\Microsoft\Framework\Silverlight\v5.0
sonar.dotnet.excludeGeneratedCode=true
sonar.dotnet.4.0.sdk.directory=C:/WIndows/Microsoft.NET/Framework/v4.0.30319
sonar.dotnet.version=4.0
sonar.gallio.runner=IsolatedProcess
sonar.gallio.coverage.tool=OpenCover
sonar.donet.visualstudio.testProjectPattern=**.Tests; **.UnitTests
sonar.opencover.installDirectory=C:/Program Files (x86)/OpenCover
sonar.dotnet.test.assemblies=FooUnitTests\bin\Release\FooUnitTests.dll
它成功运行但在日志中我看到Gallio没有执行:
No assembly to check with Gendarme
Skipping the non generated assembly of project : Foo
No assembly to check with NDeps
Gallio won't execute as there are no test projects.
任何帮助将不胜感激
答案 0 :(得分:1)
仔细检查您的测试项目模式:
sonar.donet.visualstudio.testProjectPattern=**.Tests; **.UnitTests
试试这个:
sonar.donet.visualstudio.testProjectPattern=*Tests;*UnitTests
此外,在声纳 - 跑步者输出的顶部(在前20行左右)中,您应该看到如下所示的一些行:
05:40:07.021 INFO - Initializing Hibernate
05:40:13.601 INFO - Load project settings
05:40:13.653 INFO - The following 'sln' file has been found and will be used: C:\TeamCity\buildAgent\work\920b95942ca1a758\Sonar\MyProject-Sonar.sln
05:40:17.276 INFO - The project 'MyProject.Tests' has been qualified as a test project.
05:40:19.235 INFO - The project 'MyOther.Project.Tests' has been qualified as a test project.
如果您没有看到这一点,请尝试使用-X
运行sonar-runner以启用调试输出。这应该为您提供有关用于匹配测试项目的模式的更多详细信息。
此外,任何路径都需要使用正斜杠(/
),因此需要更改以下内容:
sonar.silverlight.4.mscorlib.location=C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0
sonar.dotnet.test.assemblies=FooUnitTests\bin\Release\FooUnitTests.dll
对此:
sonar.silverlight.4.mscorlib.location=C:/Program Files (x86)/Reference Assemblies/Microsoft/Framework/Silverlight/v5.0
sonar.dotnet.test.assemblies=FooUnitTests/bin/Release/FooUnitTests.dll