I'm running Sonar on a .NET C# project.
The measurements are showing, but the coverage widget is showing 0.0% and no unit tests are executed.
I'm probably doing something wrong in my configuration, can someone help spot it?
I'm using TeamCity Enterprise 8.0.4 to run sonar-runner.bat version 2.0 on a SonarQube server version 3.7.2
TeamCity sets dotCover as the coverage tool.
The sonar-project.properties file contains:
# Project identification values
sonar.projectKey=edd-datamodel-dotnet
sonar.projectName=EDDI DataModel NET
# Info required for Sonar
sonar.sources=.
sonar.language=cs
sonar.dotnet.visualstudio.testProjectPattern=*Tests.Unit*
# Project Information
sonar.links.homepage=http://localhost/wiki
sonar.links.ci=http://localhost:8080/viewType.html?buildTypeId=bt37
sonar.links.issue=http://localhost/secure/IssueNavigator.jspa?mode=hide&requestId=11509
sonar.links.scm=scm:svn:http://localhost/SVG/repos/Product/Microsoft.Net/EDDI
and the logs of the execution:
DEBUG - Using directory D:\work\9ff348aa7c3c7d93\Barclays.EDD.DataModel.Tests.Unit\bin\Debug for project Barclays.EDD.DataModel.Tests.Unit with buildconfiguration Debug
DEBUG - Executing Gallio program...
DEBUG - - Gallio executable : C:\Program Files\Gallio\bin\Gallio.Echo.exe
DEBUG - - OpenCover executable: C:\Program Files (x86)\JetBrains\dotCover\v2.1\Bin\dotCover.exe
DEBUG - - Coverage tool : dotCover
DEBUG - - Runner : LOCAL
DEBUG - - Report directory : D:\work\9ff348aa7c3c7d93\.sonar
DEBUG - - Report file : gallio-report
DEBUG - - Test assemblies :
DEBUG - D:\work\9ff348aa7c3c7d93\Barclays.EDD.DataModel.Tests.Unit\bin\Debug\Barclays.EDD.DataModel.Tests.Unit.dll
DEBUG - - Working directory : D:\work\9ff348aa7c3c7d93\.sonar
DEBUG - - dotCover include:
DEBUG - - dotCover exclude:
DEBUG - - Coverage report: D:\work\9ff348aa7c3c7d93\.sonar\coverage-report.xml
INFO - Executing command: C:\Program Files (x86)\JetBrains\dotCover\v2.1\Bin\dotCover.exe a /TargetExecutable=C:\Program Files\Gallio\bin\Gallio.Echo.exe /TargetWorkingDir=D:\work\9ff348aa7c3c7d93\.sonar "/TargetArguments=\"/r:Local\" \"/report-directory:D:\work\9ff348aa7c3c7d93\.sonar\" \"/report-name-format:gallio-report\" \"/report-type:Xml\" \"D:\work\9ff348aa7c3c7d93\Barclays.EDD.DataModel.Tests.Unit\bin\Debug\Barclays.EDD.DataModel.Tests.Unit.dll\"" /Filters=+:module=Barclays.EDD.DataModel;class=*;function=*;+:module=Build;class=*;function=*; /ReportType=TeamCityXML /Output=D:\work\9ff348aa7c3c7d93\.sonar\coverage-report.xml
INFO - JetBrains dotCover Console Runner v2.1.471.44. Copyright (c) 2009-2014 JetBrains s.r.o. All rights reserved.
INFO -
DEBUG - Updating semaphore batch-edd-datamodel-dotnet
INFO - [JetBrains dotCover] Coverage session started [26/05/2014 15:31:14]
INFO -
INFO - Gallio Echo - Version 3.4 build 11
INFO - Get the latest version at http://www.gallio.org/
INFO -
INFO - Start time: 15:31
INFO - Initializing the runtime and loading plugins.
INFO - Verifying test files.
INFO - Initializing the test runner.
INFO - test runner.' flowId='eac27e3d045b896d
INFO - Running the tests.
INFO - Running tests.' flowId='eac27e3d045b896d
INFO - Barclays.EDD.DataModel.Tests.Unit (2s)
DEBUG - Updating semaphore batch-edd-datamodel-dotnet
INFO -
INFO -
INFO - Generating reports.
INFO - Disposing the test runner.
INFO - Disposed test runner.' flowId='eac27e3d045b896d
INFO - Stop time: 15:31 (Total execution time: 5.500 seconds)
INFO -
INFO - 0 run, 0 passed, 0 failed, 0 inconclusive, 0 skipped
INFO -
INFO - [JetBrains dotCover] Coverage session finished [26/05/2014 15:31:28]
Any help would be appreciated!
Thanks,
Eyal
This looks unusual
DEBUG - - OpenCover executable: C:\Program Files (x86)\JetBrains\dotCover\v2.1\Bin\dotCover.exe
DEBUG - - Coverage tool : dotCover
The OpenCover executable is actually OpenCover.Console.exe
Are you trying to run OpenCover or dotCover?
I had similar problem. The solution was to add:
sonar.gallio.runner=IsolatedProcess
Full content of my sonar-project.properties file: https://sonartfs.codeplex.com/
Related
We are running SonarQube Community Edition Version 7.9.1 (build 27448) (the currently latest docker image)
I have some nUnit tests but I'm struggling to get the code coverage data imported to SonarQube.
I have successfully used SonarScanner.MSBuild (sonar-scanner-msbuild-4.6.2.2108-net46) to import the code analysis and number of nUnit tests to SonarQube using the following commands:
SonarScanner.MSBuild.exe begin /k:"ProjectName" /d:sonar.host.url="..." /d:sonar.login="..." /d:sonar.cs.nunit.reportsPaths="NUnitResults.xml"
MSBuild.exe ....sln /t:Rebuild
nunit3-console.exe --result=NUnitResults.xml path\to\tests.dll
SonarScanner.MSBuild.exe end /d:sonar.login="..."
Now I want to use OpenCover to get the code coverage info to SonarQube so I'm using the following commands
SonarScanner.MSBuild.exe begin /k:"ProjectName" /d:sonar.host.url="..." /d:sonar.login="..." /d:sonar.cs.nunit.reportsPaths="NUnitResults.xml" /d:sonar.cs.opencover.reportsPaths="opencover.xml"
MSBuild.exe ....sln /t:Rebuild
nunit3-console.exe --result=NUnitResults.xml path\to\tests.dll
OpenCover.Console.exe -output:opencover.xml -register:user -target:"nunit3-console.exe" -targetargs:"path\to\tests.dll --result=NUnitResults.xml"
SonarScanner.MSBuild.exe end /d:sonar.login="..."
[I think I'm probably unnecessarily running the nUnit tests twice, but I'll sort that out once I've resolved the following issue]
The problem is I'm not getting any code coverage details on SonarQube.
Checking the SonarScanner log I can see the following output from OpenCover:
Executing: nunit3-console.exe
NUnit Console Runner 3.10.0 (.NET 2.0)
Copyright (c) 2019 Charlie Poole, Rob Prouse
06 September 2019 09:24:53
Runtime Environment
OS Version: Microsoft Windows NT 10.0.14393.0
CLR Version: 4.0.30319.42000
Test Files
path\to\UnitTests.dll
Run Settings
DisposeRunners: True
WorkDirectory: ...
ImageRuntimeVersion: 4.0.30319
ImageTargetFrameworkName: .NETFramework,Version=v4.6.1
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
NumberOfTestWorkers: 8
Test Run Summary
Overall result: Passed
Test Count: 35, Passed: 35, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
Start time: 2019-09-06 08:24:54Z
End time: 2019-09-06 08:24:57Z
Duration: 3.111 seconds
Results (nunit3) saved as NUnitResults.xml
Committing...
Visited Classes 12 of 12 (100)
Visited Methods 41 of 41 (100)
Visited Points 240 of 240 (100)
Visited Branches 41 of 41 (100)
==== Alternative Results (includes all methods including those without corresponding source) ====
Alternative Visited Classes 12 of 12 (100)
Alternative Visited Methods 41 of 53 (77.36)
Now checking the dir I can see I have NUnitResults.xml and opencover.xml created and populated. (I don't really know how to read OpenCover results but it has data for my unit tests)
The SonarScanner.MSBuild.exe end log has this tidbit:
INFO: Sensor C# Tests Coverage Report Import [csharp]
INFO: Parsing the OpenCover report path.\opencover.xml
INFO: Adding this code coverage report to the cache for later reuse: path.\opencover.xml
WARN: The Code Coverage report doesn't contain any coverage data for the included files. For troubleshooting hints, please refer to https://docs.sonarqube.org/x/CoBh
INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=14ms
INFO: Sensor C# Unit Test Results Import [csharp]
INFO: Parsing the NUnit Test Results file path.\NUnitResults.xml
INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=34ms
Now the classes that the unit tests cover are included (I can see them in SonarQube marked as uncovered) so I guess either OpenCover isn't collecting the correct info or something is going wrong matching the covered files with the file in the solution.
n.b. Checking the project that should be covered by these tests, under Project > Build > Advanced the Debug Info is set to full for Debug configuration, which some resources seem to suggest is required.
Any idea what I'm missing/where I'm going wrong?
UPDATE
Checking the bottom of opencode.xml it has the following:
<Module skippedDueTo="MissingPdb" hash="DD-83-09-69-9F-A7-11-FF-F5-BC-43-7C-87-B2-54-99-0D-A5-D5-61">
<ModulePath>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\MyCompany.Common.Utility\v4.0_1.0.0.0__bf95fa7f15863c9f\MyCompany.Common.Utility.dll</ModulePath>
<ModuleTime>2019-09-05T16:07:28.6111533Z</ModuleTime>
<ModuleName>MyCompany.Common.Utility</ModuleName>
<Classes />
</Module>
The original authors of this solution seemed to like shoving everything in the GAC, so I'm guessing OpenCover is looking in the GAC rather than locally for the dll, and the GAC doesn't hold pdbs.
I tried setting the OpenCover -targetdir setting as suggested in the manual:
The path to the target directory; if the target argument already contains a path then this argument can be used to provide an alternate path where PDB files may be found.
I also tried to use -searchdirs (Alternative locations to look for PDBs.)
but neither of them resolved it.
Can I tell OpenCover to use the bin\Debug pdbs?
https://github.com/OpenCover/opencover/wiki/Usage#notes-on-spaces-in-arguments
Using \" in targetargs to represent quotes to nunit3-console
SonarScanner.MSBuild.exe begin /k:"ProjectName" /d:sonar.host.url="..." /d:sonar.login="..." /d:sonar.cs.nunit.reportsPaths="NUnitResults.xml" /d:sonar.cs.opencover.reportsPaths="opencover.xml"
MSBuild.exe ....sln /t:Rebuild
OpenCover.Console.exe -output:opencover.xml -register:user -target:"nunit3-console.exe" -targetargs:"\"path\to\tests.dll\" --result=NUnitResults.xml"
SonarScanner.MSBuild.exe end /d:sonar.login="..."
Step1 : SonarScanner.MSBuild.exe begin /k:"Project-Name" /d:sonar.cs.opencover.reportsPaths=%cd%\TestCoverResult.xml /d:sonar.exclusions="**/*.css,**/*.js,**/*.cshtml" /d:sonar.verbose="true" /d:sonar.host.url="https://host-url.com/" /d:sonar.login="Login-Token"
Step2 : "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" /t:Rebuild
Step3 : ".\packages\OpenCover.4.7.1221\tools\OpenCover.Console.exe" "-target:.\packages\NUnit.ConsoleRunner.3.12.0\tools\nunit3-console.exe" "-targetargs:.\Test-Project\bin\Debug\Test-Project.dll" "-output:.\TestCoverResult.xml" -register:user
Step4 : SonarScanner.MSBuild.exe end
Explanation:
1 : reportsPath: specifies the path of the code-coverage result file.
2 : ".\packages\OpenCover.4.7.1221\tools\OpenCover.Console.exe" : it is system path of the "OpenCover.Console.exe"
3 : ".\packages\NUnit.ConsoleRunner.3.12.0\tools\nunit3-console.exe" : it is system path of the "nunit3-console.exe"
I've been struggling with this issue for a few days now and I can't seem to pinpoint what I'm doing wrong.
I've been trying to analyze a c# project that is build with travis CI and analyzed in sonarcloud.
I've set up travis (see: https://travis-ci.org/ShiveringSquirrel/heroes-app-webapi) to build and it seems to work fine.
Configuration
See .travis.yml
language: csharp
solution: heroes-app-webapi.sln
dist: trusty
sudo: required
mono:
- latest
install:
- nuget restore heroes-app-webapi.sln
- nuget install NUnit.Console -Version 3.9.0 -OutputDirectory testrunner
addons:
sonarcloud:
organization: "shiveringsquirrel-github"
token:
secure: $SONAR_TOKEN
script:
- msbuild /p:Configuration=Release /target:rebuild heroes-app-webapi.sln
- mono ./testrunner/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe ./heroes-app-webapi.Tests/bin/Release/heroes-app-webapi.Tests.dll
- sonar-scanner -Dsonar.projectVersion=1.$TRAVIS_BUILD_NUMBER
cache:
directories:
- '$HOME/.sonar/cache'
git:
clone: true
quiet: false
depth: false
submodules: true
# blocklist
branches:
except:
- legacy
- experimental
# safelist
branches:
only:
- master
- stable
See sonar-project.properties
sonar.projectKey=ShiveringSquirrel_heroes-app-webapi
sonar.projectName=heroes-app-webapi
#sonar.projectVersion=1.0
sonar.projectDescription=The backend API for the Heroes test application
sonar.links.homepage=https://github.com/ShiveringSquirrel/heroes-app-webapi
sonar.links.ci=https://travis-ci.org/ShiveringSquirrel/heroes-app-webapi
sonar.links.scm=https://github.com/ShiveringSquirrel/heroes-app-webapi
sonar.links.issue=https://github.com/ShiveringSquirrel/heroes-app-webapi/issues
#sonar.sources=.
#sonar.sources=src/main
#sonar.tests=src/test
sonar.sources=heroes-app-webapi
sonar.tests=heroes-app-webapi.Tests
sonar.scm.provider=git
sonar.scm.forceReloadAll=true
sonar.dotnet.visualstudio.testProjectPattern=*.Test
sonar.language=cs
sonar.sourceEncoding=UTF-8
sonar.verbose=true
sonar.exclusions=**/*.xml
sonar.inclusions=**/*.cs
sonar.cs.nunit.reportsPaths=TestResult.xml
Building
The full build log for travis: See full build log
Some relevant snippets form the log:
$ mono --version
Mono JIT compiler version 5.20.1.19 (tarball Thu Apr 11 09:05:42 UTC 2019)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
Interpreter: yes
LLVM: yes(600)
Suspend: hybrid
GC: sgen (concurrent by default)
$ msbuild /version
Microsoft (R) Build Engine version 16.0.0.0 for Mono
Copyright (C) Microsoft Corporation. All rights reserved.
Building with msbuild
$ msbuild /p:Configuration=Release /target:rebuild heroes-app-webapi.sln
....
302 Warning(s)
0 Error(s)
Time Elapsed 00:00:06.94
The command "msbuild /p:Configuration=Release /target:rebuild heroes-app-webapi.sln" exited with 0.
Unit testing
$ mono ./testrunner/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe ./heroes-app-webapi.Tests/bin/Release/heroes-app-webapi.Tests.dll
....
Test Run Summary
Overall result: Passed
Test Count: 25, Passed: 25, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
Start time: 2019-07-14 21:00:34Z
End time: 2019-07-14 21:00:36Z
Duration: 2.559 seconds
Results (nunit3) saved as TestResult.xml
The command "mono ./testrunner/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe ./heroes-app-webapi.Tests/bin/Release/heroes-app-webapi.Tests.dll" exited with 0.
Sonar-scanner
$ sonar-scanner -Dsonar.projectVersion=1.$TRAVIS_BUILD_NUMBER
...
21:00:40.716 DEBUG: Plugins:
...
21:00:40.717 DEBUG: * SonarC# 7.15.0.8572 (csharp)
...
21:00:46.518 DEBUG: 77 non excluded files in this Git repository
21:00:46.541 DEBUG: 'heroes-app-webapi/Global.asax.cs' indexed with language 'cs'
21:00:46.549 DEBUG: 'heroes-app-webapi/Attributes/JwtAuthenticationAttribute.cs' indexed with language 'cs'
...
21:00:46.802 INFO: 30 files indexed
21:00:46.803 INFO: 0 files ignored because of inclusion/exclusion patterns
21:00:46.804 INFO: 0 files ignored because of scm ignore settings
21:00:46.805 INFO: Quality profile for cs: Sonar way
21:00:46.806 INFO: ------------- Run sensors on module heroes-app-webapi
...
21:00:51.019 INFO: Sensor C# Properties [csharp]
21:00:51.021 WARN: No Roslyn issues report found for this project.
...
21:00:51.052 INFO: Sensor C# Unit Test Results Import [csharp]
21:00:51.054 INFO: Parsing the NUnit Test Results file /home/travis/build/ShiveringSquirrel/heroes-app-webapi/./TestResult.xml
...
21:00:51.713 INFO: SCM provider for this project is: git
21:00:51.715 INFO: 27 files to be analyzed
...
21:00:52.065 INFO: 27/27 files analyzed
21:00:52.068 INFO: Calculating CPD for 0 files
21:00:52.078 INFO: CPD calculation finished
21:00:52.235 INFO: Analysis report generated in 151ms, dir size=190 KB
21:00:52.288 INFO: Analysis report compressed in 51ms, zip size=56 KB
21:00:52.289 INFO: Analysis report generated in /home/travis/build/ShiveringSquirrel/heroes-app-webapi/.scannerwork/scanner-report
21:00:52.290 DEBUG: Upload report
21:00:52.630 DEBUG: POST 200 https://sonarcloud.io/api/ce/submit?organization=shiveringsquirrel-github&projectKey=ShiveringSquirrel_heroes-app-webapi&projectName=heroes-app-webapi | time=338ms
21:00:52.633 INFO: Analysis report uploaded in 343ms
21:00:52.637 INFO: ANALYSIS SUCCESSFUL, you can browse https://sonarcloud.io/dashboard?id=ShiveringSquirrel_heroes-app-webapi
21:00:52.637 INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
21:00:52.639 INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AWvySdH4BABcSdLoSktk
21:00:52.640 DEBUG: Report metadata written to /home/travis/build/ShiveringSquirrel/heroes-app-webapi/.scannerwork/report-task.txt
21:00:52.646 DEBUG: Post-jobs :
21:00:52.650 INFO: Analysis total time: 11.885 s
21:00:52.652 INFO: ------------------------------------------------------------------------
21:00:52.656 INFO: EXECUTION SUCCESS
21:00:52.658 INFO: ------------------------------------------------------------------------
21:00:52.662 INFO: Total time: 15.232s
21:00:52.860 INFO: Final Memory: 34M/349M
21:00:52.860 INFO: ------------------------------------------------------------------------
21:00:52.860 DEBUG: Execution getVersion
21:00:52.860 DEBUG: Execution stop
The command "sonar-scanner -Dsonar.projectVersion=1.$TRAVIS_BUILD_NUMBER" exited with 0.
So to me it all looks pretty good, only in sonarcloud.io (https://sonarcloud.io/dashboard?id=ShiveringSquirrel_heroes-app-webapi) I see nothing is analyzed.
Not even lines of code, it did update my build number and other settings. But no report or analysis. If I look at the background task:
21:00:52.639 INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AWvySdH4BABcSdLoSktk
It says "success". The other thing I've tried to investigate is the one warning I have:
21:00:51.021 WARN: No Roslyn issues report found for this project.
But it seems to me from the log that everything is analyzed properly...
Any ideas?
I am having an issue with SonarQube 6.7 where it is not displaying any C# code issues or bugs, during the analysis I can see C# is being analysed and the build is successful but when I check the SonarQube Dashboard it is only showing Typescript and XML.
I am using Jenkins to build the project using Mono as all our building is done on Ubuntu 16.04.
Setup as follows:
Jenkins 2.89.2 on Ubuntu 16.04
SonarQube Version 6.7 (build 33306) on Ubuntu 16.04 (Separate server)
Sonar C# 6.8.1
SonarQube Scanner for MSBuild 4.0.1
Mono 5.10.0 Stable
Using a Pipeline In Jenkins I am doing the following:
node {
sh 'mono ~/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/MSBuild/SonarQube.Scanner.MSBuild.exe begin /key:12345678FAKEKEY9l02998745'
sh 'dotnet restore WSP1.sln'
sh 'dotnet msbuild WSP1.sln'
sh 'mono ~/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/MSBuild/SonarQube.Scanner.MSBuild.exe end' } }
The above pipeline script works without any issues.
When I run this pipeline I can see that the C# code is being Analysed, this is just a snippet of code being analysed:
Services/Project1/Services/Project1EventsShould.cs(130,21): warning S1186: Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation. [/var/lib/jenkins/workspace/CSharpAnalysis/WSP1/test/Unit/Unit.csproj]
Services/Project1/Services/Project1EventsShould.cs(137,21): warning S1186: Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation. [/var/lib/jenkins/workspace/CSharpAnalysis/WSP1/test/Unit/Unit.csproj]
Services/Project1/Models/ZenEventShould.cs(24,17): warning S1481: Remove this unused 'date' local variable. [/var/lib/jenkins/workspace/CSharpAnalysis/WSP1/test/Unit/Unit.csproj]
Services/Project1/Models/CollaborationUserShould.cs(16,17): warning S1481: Remove this unused 'sut' local variable. [/var/lib/jenkins/workspace/CSharpAnalysis/WSP1/test/Unit/Unit.csproj]
At the end I get a SUCCESS, everything looks good but when I check SonarQube I can see that the uploaded code is being analysed for display in SonarQube, this usually takes a minute or so but when this is completed I can see that only TypeScript and XML is displayed.
In amongst the output I get some warnings, info and errors but nothing looks sinister, at the end of the output I get the success message
INFO: 68 files had no CPD blocks
INFO: Calculating CPD for 281 files
INFO: CPD calculation finished
INFO: Analysis report generated in 1771ms, dir size=5 MB
INFO: Analysis reports compressed in 3908ms, zip size=2 MB
INFO: Analysis report uploaded in 5866ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://sonar.serverdomain.com:9000/dashboard/index/12345678FAKEKEY9l02998745
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://sonar.serverdomain.com:9000/api/ce/task?id=AKsdHc7FAKEIDVOeCzBYv
INFO: Task total time: 1:32.107 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:42.735s
INFO: Final Memory: 54M/397M
INFO: ------------------------------------------------------------------------
The SonarQube Scanner has finished
14:59:57.577 Creating a summary markdown file...
14:59:57.59 Analysis results: http://sonar.serverdomain.com:9000/dashboard/index/12345678FAKEKEY9l02998745
14:59:57.591 Post-processing succeeded.
Finished: SUCCESS
I have the full output handy, I just need to sanitize this to remove anything that may be sensitive, if you would like a look just let me know and I will post this.
I am pretty new to SonarQube so the issue I am having could be something silly but I have been ripping my hair out trying to figure this out.
EDIT : I was digging through the output again and noticed 2 warning in the following:
INFO: Quality profile for cs: Sonar way
INFO: Quality profile for ts: Sonar way
INFO: Quality profile for xml: Sonar way
INFO: Sensor C# Properties [csharp]
WARNING: WARN: Property missing: 'sonar.cs.analyzer.projectOutPaths'. No protobuf files will be loaded for this project.
WARNING: WARN: No roslyn issues report not found for this project.
INFO: Sensor C# Properties [csharp] (done) | time=1ms
I just ran into the same issue on Sonarqube 6.7.4 (build 38452).
Solved by two steps:
After updating the built-in SonarC# plugin to version 7.2 (build 5463) (Uninstall-Restart-Install-Restart), and re-scanning, code issues (vulnerabilities, code smells, etc) showed up.
Introduced package coverlet.msbuild into test projects to generate coverage data, configured Project - Administration - C# - OpenCover Unit Tests Reports Paths to use path/to/coverage.opencover.xml. After re-scanning, test coverage data showed up.
Here are all the commands executed after above configurations:
dotnet path/to/SonarScanner.MSBuild.dll begin /k:"project-key"
dotnet build
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
dotnet path/to/SonarScanner.MSBuild.dll end
I am trying to get the C# unit test coverage.
Below is my sonar setup, but when I run sonar runner I don't see any thing related to
unite test coverage and the result on browser it does not show any unit test
coverage.
My question is: the sonar c# plugin page says that gallio is installed as part of it. I am assuming that I need not have to install gallio externally but when I run sonar runner, it invokes gallio which in turn invokes opencover to get the coverage ?
What am i doing wrong ?
# Required metadata
sonar.projectKey=MyProg
sonar.projectName=MyProg
sonar.projectVersion=1.0
# sonar.sources=C:/MyProj
sonar.sources=.
sonar.language=cs
# Encoding of the source code
sonar.sourceEncoding=UTF-8
# Additional parameters
# sonar.my.property=value
#Core C# Settings
sonar.dotnet.visualstudio.solution.file=AS.sln
sonar.dotnet.excludeGeneratedCode=true
sonar.dotnet.4.0.sdk.directory=C:/Windows/Microsoft.NET/Framework/v4.0.30319
sonar.dotnet.version=4.0
#Gendarme
sonar.gendarme.mode=
# Gallio / Unit Tests
sonar.gallio.mode=
sonar.gallio.coverage.tool=OpenCover
sonar.gallio.runner=IsolatedProcess
sonar.dotnet.visualstudio.testProjectPattern=*Test*
sonar.opencover.installDirectory=C:/opencover.4.5.2506/
# FXCop
sonar.fxcop.mode=skip
# StyleCop
sonar.stylecop.mode=skip
# NDeps
sonar.ndeps.mode=skip
I am not finding any information about gallio in sonar log:
c:\Program Files\sonar-runner-dist-2.4\sonar-runner-2.4\bin\..
SonarQube Runner 2.4
Java 1.7.0_40 Oracle Corporation (64-bit)
Windows 7 6.1 amd64
INFO: Error stacktraces are turned on.
INFO: Runner configuration file: c:\Program Files\sonar-runner-dist-2.4\sonar-runner-2.4\bin\..\conf\sonar-runner.properties
INFO: Project configuration file: C:\cna2\Columbus-NA\ERP\SourceCode\Projects\AS\sonar-project.properties
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: C:\cna2\Columbus-NA\ERP\SourceCode\Projects\AS\.\.sonar
INFO: SonarQube Server 4.5
18:30:31.202 INFO - Load global referentials...
18:30:31.309 INFO - Load global referentials done: 109 ms
18:30:31.316 INFO - User cache: C:\Users\vikas.c\.sonar\cache
18:30:31.323 INFO - Install plugins
18:30:31.433 INFO - Install JDBC driver
18:30:31.438 INFO - Create JDBC datasource for jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
18:30:32.494 INFO - Initializing Hibernate
18:30:33.577 INFO - Load project referentials...
18:30:33.829 INFO - Load project referentials done: 253 ms
18:30:33.829 INFO - Load project settings
18:30:34.207 INFO - Loading technical debt model...
18:30:34.234 INFO - Loading technical debt model done: 27 ms
18:30:34.236 INFO - Apply project exclusions
18:30:34.438 INFO - ------------- Scan Sage AS
18:30:34.442 INFO - Load module settings
18:30:34.603 INFO - Language is forced to cs
18:30:34.603 INFO - Loading rules...
18:30:35.074 INFO - Loading rules done: 471 ms
18:30:35.091 INFO - Configure Maven plugins
18:30:35.147 INFO - Compare to previous analysis (2014-10-06)
18:30:35.153 INFO - Compare over 30 days (2014-09-06, analysis of 2014-10-06 13:42:43.0)
18:30:35.154 INFO - No quality gate is configured.
18:30:35.267 INFO - Base dir: C:\cna2\Columbus-NA\ERP\SourceCode\Projects\AS\.
18:30:35.267 INFO - Working dir: C:\cna2\Columbus-NA\ERP\SourceCode\Projects\AS\.\.sonar
18:30:35.268 INFO - Source paths: .
18:30:35.268 INFO - Source encoding: UTF-8, default locale: en_US
18:30:35.268 INFO - Index files
18:30:35.599 INFO - 132 files indexed
18:30:46.573 INFO - Quality profile for cs: Sonar way
18:30:46.696 INFO - All FxCop rules are disabled, skipping its execution.
18:30:46.699 INFO - Sensor QProfileSensor...
18:30:46.704 INFO - Sensor QProfileSensor done: 5 ms
18:30:46.704 INFO - Sensor InitialOpenIssuesSensor...
18:30:46.729 INFO - Sensor InitialOpenIssuesSensor done: 25 ms
18:30:46.729 INFO - Sensor ProjectLinksSensor...
18:30:46.733 INFO - Sensor ProjectLinksSensor done: 4 ms
18:30:46.734 INFO - Sensor VersionEventsSensor...
18:30:46.856 INFO - Sensor VersionEventsSensor done: 122 ms
18:30:46.856 INFO - Sensor FileHashSensor...
18:30:46.878 INFO - Sensor FileHashSensor done: 22 ms
18:30:46.878 INFO - Sensor org.sonar.plugins.csharp.squid.CSharpSquidSensor#643926a2...
18:30:46.925 INFO - 132 source files to be analyzed
18:30:47.818 INFO - 132/132 source files analyzed
18:30:48.015 INFO - Sensor org.sonar.plugins.csharp.squid.CSharpSquidSensor#643926a2 done: 1137 ms
18:30:48.015 INFO - Sensor CPD Sensor (wrapped)...
18:30:48.015 INFO - DefaultCpdEngine is used for cs
18:30:48.021 INFO - Cross-project analysis disabled
18:30:48.601 INFO - Sensor CPD Sensor (wrapped) done: 586 ms
18:30:48.830 INFO - Execute decorators...
18:30:50.537 INFO - Store results in database
18:30:53.723 INFO - ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/SageCNAAS
18:30:53.779 INFO - Executing post-job class org.sonar.plugins.core.issue.notification.SendIssueNotificationsPostJob
18:30:53.781 INFO - Executing post-job class org.sonar.plugins.core.batch.IndexProjectPostJob
18:30:53.823 INFO - Executing post-job class org.sonar.plugins.dbcleaner.ProjectPurgePostJob
18:30:53.838 INFO - -> Keep one snapshot per day between 2014-09-08 and 2014-10-05
18:30:53.839 INFO - -> Keep one snapshot per week between 2013-10-07 and 2014-09-08
18:30:53.840 INFO - -> Keep one snapshot per month between 2009-10-12 and 2013-10-07
18:30:53.841 INFO - -> Delete data prior to: 2009-10-12
18:30:53.849 INFO - -> Clean Sage AS [id=1]
18:30:53.854 INFO - <- Clean snapshot 1850
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
Total time: 23.752s
Final Memory: 16M/675M
INFO: ------------------------------------------------------------------------
First of all you have to define the test project pattern. sonar/opencover is not able to identify your test binaries. Secondly, if you are using sonar 4.3+ than you may want to know that sonar has ended its support for gallio and opencover. In this case you need to import coverage xml from outside to get you coverage. Please enhance your post with suitable information about version of sonar etc.
Environment: Windows 7 | SonarQube 4.4 | SonarRunner 2.4 | .NET (C#)
I have been using Sonar 3.2 & SonarRunner 2.0. Projects are being displayed in Sonar dashboard upon typing "sonar-runner" in command prompt, where project base directory is there.
With the same set of configurations, when I upgrade to SonarQube 4.4 & SonarRunner 2.4, following exceptions are thrown upon typing "sonar-runner" in command prompt, where project base directory is there:
C:\Users\kprasad\Documents\Visual Studio 2013\Projects\LKTest>sonar-runner
C:\Users\kprasad\Downloads\sonar-runner-2.4
SonarQube Runner 2.4
Java 1.6.0_38-ea Sun Microsystems Inc. (32-bit)
Windows 7 6.1 x86
INFO: Runner configuration file: C:\Users\kprasad\Downloads\sonar-runner-2.4\con
f\sonar-runner.properties
INFO: Project configuration file: C:\Users\kprasad\Documents\Visual Studio 2013\
Projects\LKTest\sonar-project.properties
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: C:\Users\kprasad\Documents\Visual Studio 2013\Projects\LKT
est\.\.sonar
INFO: SonarQube Server 4.4.1
18:49:01.343 INFO - Load global settings
18:49:01.436 INFO - User cache: C:\Users\kprasad\.sonar\cache
18:49:01.447 INFO - Install plugins
18:49:02.087 INFO - Install JDBC driver
18:49:02.094 WARN - H2 database should be used for evaluation purpose only
18:49:02.094 INFO - Create JDBC datasource for jdbc:h2:tcp://localhost/sonar
18:49:02.164 INFO - Initializing Hibernate
18:49:05.018 INFO - Loading technical debt model...
18:49:05.042 INFO - Loading technical debt model done: 24 ms
18:49:05.047 INFO - Load project settings
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 4.283s
Final Memory: 37M/89M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with t
he -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
C:\Users\kprasad\Documents\Visual Studio 2013\Projects\LKTest>
sonar project properties:
sonar.projectKey=LKTest Sonar Report
sonar.projectVersion=1.0
sonar.projectName=LKTest
sonar.sources=.
sonar.language=cs
sonar.sourceEncoding=UTF-8
sonar.visualstudio.enable=true
sonar.cs.opencover.reportPaths=results.xml
sonar.dotnet.visualstudio.solution.file=LKTest.sln
sonar.silverlight.4.mscorlib.location=C:/Program Files/Reference Assemblies/Microsoft/Framework/Silverlight/v4.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.gendarme.mode=
sonar.gallio.mode=
sonar.gallio.coverage.tool=OpenCover
sonar.gallio.runner=Local
sonar.dotnet.visualstudio.testProjectPattern=*.Test*
sonar.gallio.reports.path=gallio-report.xml
sonar.gallio.coverage.reports.path=coverage-report.xml
sonar.opencover.installDirectory=C:/Program Files/OpenCover/
sonar.dotnet.test.assemblies=C:\Users\kprasad\Documents\Visual Studio 2013\Projects\LKTest\LKTest.Tests\bin\Debug\LKTest.Tests.dll
sonar.fxcop.mode=reusereport
sonar.stylecop.mode=reusereport
sonar.ndeps.mode=reusereport
PFB the output when I re-run "sonar-runner -e" in command prompt, where the project base directory is there:
C:\Users\kprasad\Documents\Visual Studio 2013\Projects\LKTest>sonar-runner -e
C:\Users\kprasad\Downloads\sonar-runner-2.4
SonarQube Runner 2.4
Java 1.6.0_38-ea Sun Microsystems Inc. (32-bit)
Windows 7 6.1 x86
INFO: Error stacktraces are turned on.
INFO: Runner configuration file: C:\Users\kprasad\Downloads\sonar-runner-2.4\con
f\sonar-runner.properties
INFO: Project configuration file: C:\Users\kprasad\Documents\Visual Studio 2013\
Projects\LKTest\sonar-project.properties
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: C:\Users\kprasad\Documents\Visual Studio 2013\Projects\LKT
est\.\.sonar
INFO: SonarQube Server 4.4.1
12:39:51.109 INFO - Load global settings
12:39:51.324 INFO - User cache: C:\Users\kprasad\.sonar\cache
12:39:51.344 INFO - Install plugins
12:39:51.791 INFO - Install JDBC driver
12:39:51.810 WARN - H2 database should be used for evaluation purpose only
12:39:51.811 INFO - Create JDBC datasource for jdbc:h2:tcp://localhost/sonar
12:39:51.984 INFO - Initializing Hibernate
12:39:55.507 INFO - Loading technical debt model...
12:39:55.540 INFO - Loading technical debt model done: 33 ms
12:39:55.544 INFO - Load project settings
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 6.759s
Final Memory: 37M/89M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher
.java:91)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102
)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.sonar.runner.Main.executeTask(Main.java:70)
at org.sonar.runner.Main.execute(Main.java:59)
at org.sonar.runner.Main.main(Main.java:53)
Caused by: java.lang.IllegalArgumentException
at java.net.URI.create(URI.java:841)
at org.sonar.batch.bootstrap.ServerClient.doRequest(ServerClient.java:99
)
at org.sonar.batch.bootstrap.ServerClient.request(ServerClient.java:85)
at org.sonar.batch.bootstrap.ServerClient.request(ServerClient.java:81)
at org.sonar.batch.bootstrap.ServerClient.request(ServerClient.java:77)
at org.sonar.batch.settings.DefaultSettingsReferential.downloadSettings(
DefaultSettingsReferential.java:65)
at org.sonar.batch.settings.DefaultSettingsReferential.projectSettings(D
efaultSettingsReferential.java:56)
at org.sonar.batch.bootstrap.BatchSettings.downloadSettings(BatchSetting
s.java:92)
at org.sonar.batch.bootstrap.BatchSettings.init(BatchSettings.java:71)
at org.sonar.batch.scan.ProjectSettingsReady.start(ProjectSettingsReady.
java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(
ReflectionLifecycleStrategy.java:110)
at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start(Reflect
ionLifecycleStrategy.java:89)
at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter
.start(AbstractInjectionFactory.java:84)
at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.j
ava:169)
at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Store
d.java:132)
at org.picocontainer.behaviors.Stored.start(Stored.java:110)
at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(Defaul
tPicoContainer.java:1015)
at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoConta
iner.java:1008)
at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.jav
a:766)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentCo
ntainer.java:91)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.
java:77)
at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:64)
at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:51)
at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.ja
va:110)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentCo
ntainer.java:92)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.
java:77)
at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapCon
tainer.java:185)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java
:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher
.java:87)
... 9 more
Caused by: java.net.URISyntaxException: Illegal character in query at index 80:
http://localhost:9025/batch_bootstrap/properties?dryRun=false&project=LKTest
Sonar Report
at java.net.URI$Parser.fail(URI.java:2810)
at java.net.URI$Parser.checkChars(URI.java:2983)
at java.net.URI$Parser.parseHierarchical(URI.java:3073)
at java.net.URI$Parser.parse(URI.java:3015)
at java.net.URI.<init>(URI.java:577)
at java.net.URI.create(URI.java:839)
... 47 more
ERROR:
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
C:\Users\kprasad\Documents\Visual Studio 2013\Projects\LKTest>
Please help in sorting out these exceptions & let me know if any additional details are required, thanks.
Regards,
KP
The problem is that your "sonar.projectKey" contains space characters.
In recent versions of SonarQube, we enforced the kind of characters that are allowed in project keys: only letters, digits, '_', '.' and ':'. See SONAR-4188 for reference.