0
votes

I am using sonar-runner to run tests and code coverage over my C# code with the help of gallio plugin. The tests are running fine, but I am not able to see any code coverage on the sonar web UI.

sonar_code_coverage_snapshot

My Sonar settings are as follows:

sonar-project.properties mentioning only relevant bits sonar.gallio.coverage.tool = NCover sonar.NCover.installDirectory = C:/Program Files/NCover sonar.donet.visualstudio.testProjectPattern = .Test sonar.dotnet.buildConfigurations = "Release|x86"

Any idea what coule be missing??

sonar.projectKey=XXX:XXX
sonar.projectVersion=trunk
sonar.projectName=XXX
sources=.
sonar.language=cs  
sonar.dotnet.visualstudio.solution.file=Project.sln
sonar.dotnet.excludeGeneratedCode=false
sonar.dotnet.4.0.sdk.directory=C:/WIndows/Microsoft.NET/Framework/v4.0.30319
sonar.dotnet.version=4.0 
# Gallio
sonar.gallio.mode=
sonar.gallio.coverage.tool=NCover
sonar.gallio.runner=IsolatedAppDomain
sonar.NCover.installDirectory=c:/Program Files/NCover
sonar.gallio.installDirectory=C:/Program Files/Gallio
sonar.dotnet.test.assemblies=$(SolutionDir)/../**/bin/**/*.Tests.Unit.dll
# FXCop
sonar.fxcop.mode=   
#StyleCop
sonar.stylecop.mode= 
#NDeps
sonar.ndeps.mode=skip

sonar-runner.properties

2

2 Answers

1
votes

You said

sonar.dotnet.buildConfigurations = "Release|x86"

If that's true, your build likely isn't generating .pdb files, which are needed to figure out the mapping between the binaries and your source files.

Does it work if you try it with a Debug build?

0
votes

I was seeing this same behavior with NCover in Sonar. I found that Sonar was generating invalid arguments for Gallio's NCover runner.

Try piping the output from Sonar's runner into a text file so that you can examine the arguments more easily (on the command line, you can just type sonar-runner > output.txt to do this).

You will likely see a line like this in your output:

INFO  .u.c.CommandExecutor - Executing command: C:\Program Files\Gallio\bin\Gallio.Echo.exe /r:Local /report-directory:E:\Reports\.sonar /report-name-format:gallio-report /report-type:Xml E:\Projects\UnitTests\bin\Release\UnitTests.dll /runner-property:NCoverCoverageFile=E:\Reports\.sonar\coverage-report.xml /runner-property:NCoverArguments=//ias MyFirstAssembly;MySecondtAssembly;MyThirdAssembly

If you attempt to execute this manually via Gallio on the command line, you will get an error:

Cannot find file 'MyFirstAssembly;MySecondtAssembly;MyThirdAssembly'

If you edit this list manually down to a single entry such as MyFirstAssembly*, everything will work as expected.

This seems to indicate that Sonar is generating invalid command line arguments for Gallio. As much as I love NCover, the easiest solution was to use OpenCover instead.