1

我正在尝试为 C# 项目设置单元测试和代码覆盖率。我使用 sonar runner 作为分析器,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.

任何帮助将不胜感激

4

1 回答 1

1

仔细检查您的测试项目模式: sonar.donet.visualstudio.testProjectPattern=**.Tests; **.UnitTests

试试这个: sonar.donet.visualstudio.testProjectPattern=*Tests;*UnitTests

此外,在 sonar-runner 输出的顶部(在前 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.

如果您没有看到这一点,请尝试运行 sonar-runner with-X以启用调试输出。这应该为您提供有关用于匹配测试项目的模式的更多详细信息。

此外,任何路径都需要使用正斜杠 ( /),因此需要更改以下内容:

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 
于 2013-11-12T04:41:55.240 回答