I can't really see if my NUnit reports are being imported in to the SonarQube report suite while I am analyzing a .NET project with the MSBuild scanner.
I'm running SonarQube 5.4 with the SonarQube scanner for MSBuild 2.0 and C# plugin v5.0 (and other non-related plugins, as well)
d:\buildTools\sonar-runner-for-msbuild\MSBuild.SonarQube.Runner.exe begin
/k:$productKey
/n:$productName
/v:$BuildNumber
/d:sonar.cs.nunit.reportsPaths=$NunitTestOutput
While I'm passing in the correct path for the nunit.xml report, it is not being imported into the report suite on SonarQube:
I navigate to (project home) -> Dashboards -> Custom dashboard (where I have added the Unit Tests Coverage widget) but it has no more information other than the number of tests.
Just to be sure, the log also shows that the analyzer knows about the exact location of the nUnit report, but it shows no sign of failure or success either.
2016.05.11 09:28:09 INFO [o.s.s.c.t.CeWorkerCallableImpl] Execute task | project=[Redacted-project-name] | id=[redacted]
[...]
2016.05.11 09:28:11 INFO [o.s.s.c.s.LogScannerContextStep] Settings for module: [Redacted-module-name]
[...]
2016.05.11 09:28:11 INFO [o.s.s.c.s.LogScannerContextStep] - sonar.cs.fxcop.reportPath=E:\WS\12500236\source\src\[Redacted-module-name].dll.CodeAnalysisLog.xml
2016.05.11 09:28:11 INFO [o.s.s.c.s.LogScannerContextStep] - sonar.cs.nunit.reportsPaths=E:\WS\12500236\_testoutput\nunit.xml
2016.05.11 09:28:11 INFO [o.s.s.c.s.LogScannerContextStep] - sonar.cs.roslyn.reportFilePath=E:\WS\12500236\source\src\[Redacted-module-name].dll.RoslynCA_fixed.json
[...]
2016.05.11 09:28:29 INFO [o.s.s.c.t.CeWorkerCallableImpl] Executed task | project=[Redacted-project-name] | id=[redacted] | time=20328ms
What should I look for? What am I missing?
I was following this guide to import the NUnit report.
NUnit doesn't have coverage built-in. You need to use some other tool for calculating the coverage.
See Sonar's documentation on code coverage results
Related
recently we upgraded teamcity to 2017.2, after that TC is failing to import the DotCover report file. I am trying to run XUNIT meta runner: https://raw.githubusercontent.com/JetBrains/meta-runner-power-pack/master/xUnit.net-dotCover/MRPP_xunit_dotcover.xml
and updated this parameter:
[string] $dotCoverExecutable = "%teamcity.tool.JetBrains.dotCover.CommandLineTools.bundled%"
command: write-host "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='$outputFile']"
Error Message:
No available .NET Coverage report generator for type 'dotcover'. Skipped files: [D:\TCW\563efb8648d3acf2\xunitcoverage.dcvr]
i also tried generating HTML report and passed the html file to ##teamcity[importData , and getting this error:
No available .NET Coverage report generator for type 'dotcover'. Skipped files: [D:\TCW\563efb8648d3acf2\dotCoverReport.html]
Any help please?
Thanks,
Urivinty
i am able to fix the issue by adding below line to MRPP Xunit meta runner. First we need to configure code coverage engine as documented here: https://confluence.jetbrains.com/display/TCD10/Manually+Configuring+Reporting+Coverage
Write-Host "##teamcity[dotNetCoverage dotcover_home='$dotCoverExecutable']"
I'm using SonarQube 4.5.4, and the SonarQube Runner version is 2.4.
I have defined the sonar.jacoco.reportPath=jacoco/jacoco-ut.exec (the result of junit4 ant task which integrated the jacoco as coverage tool) in the sonar-project.properties file.
The exec file looks fine, it's contains all the coverage information per test, I've imported it with the EclEmma 2.3.2.201409141915 and all the coverage information is there.
In the SonarQube dashboard it's reflecting in strange way:
The cevarage is taken as Overall / IT coverage, instead of UT coverage. and the UT coverage is missing, BTW also the duplication is set to 0% (and it's not true)
from Sonar log it's looks like this:
08:24:34.604 INFO - Sensor SurefireSensor done: 713 ms
08:24:34.604 INFO - Sensor JaCoCoOverallSensor...
08:24:35.140 INFO - Analysing /ibmshome/cc/cctlg/sonar/sonar/ens-14023/./.sonar/ATT_MO_API_TlgServer_ATT_TlgServer_module/jacoco-overall.exec
08:24:52.505 INFO - No information about coverage per test.
08:24:52.505 INFO - Sensor JaCoCoOverallSensor done: 17901 ms
08:24:52.505 INFO - Sensor CoberturaSensor...
08:24:52.506 WARN - Cobertura report not found at /ibmshome/ibms/ibms/target/site/cobertura/coverage.xml
08:24:52.506 INFO - Sensor CoberturaSensor done: 1 ms
08:24:52.506 INFO - Sensor JaCoCoSensor...
08:24:52.815 INFO - Analysing /ibmshome/ibms/ibms/ccirp/proj/sbmsIrd1000/jacoco/jacoco-ut.exec
08:25:04.966 INFO - No information about coverage per test.
08:25:04.966 INFO - Sensor JaCoCoSensor done: 12460 ms
I'm looking for solution for a long time, also tried to change properties and adding sonar.jacoco.itReportPath as dummy, and also getting the same result.
You are seeing overall coverage in SonarQube because you may have the widget for Integration test enabled/set. It's not possible that you are seeing 0% in UT or IT tests but Overall is showing some valid % other than 0.
As per the snapshot you pasted, it seems like you are NOT setting sonar.tests=src/test/java or sonar.java.tests=some/test/java i.e. some valid folder value where all your test source code reside.
For getting the coverage, make sure you set either sonar.jacoco.reportPath=full/relative/path/to/the/jacoco-ut-file.exec and also set the sonar.sources, sonar.tests, sonar.jacoco.itReportPath=full/relative/path/to/jacoco-nonUT-actually-IT.exec file
NOTE: With the newer versions of SonarQube, most of the properties now have java/language name embedded in the properties i.e. sonar.binaries may now be sonar.java.binaries or sonar.groovy.binaries
See setting sonar.java.sources, sonar.java.tests, sonar.java.binaries, sonar.jacoco.reportPath but these will work as it's sonar.jacoco.itReportPath to the correct values helps!
Also, try these settings on a new project if for some reason your project in SonarQube is corrupt and now showing valid data after each evaluation.
I have below problems with SonarRunner.
SonarQube along with Sonar runner unable to pull junit format xml reports
Unit Tests or Test Coverage widget doesn't show up. It says No Data.
I am following instructions described here
I manually created report file in XML format as described, but still no luck.
Below is the XML file - TEST-Firefox_210_Mac_OS.com.company.BarTest.xml,
<testsuite name="Firefox_210_Mac_OS.com.company.BarTest" errors="0" failures="0" tests="3" time="0.0">
<testcase classname="Firefox_210_Mac_OS.com.company.BarTest" name="testfullName" time="0.0"/>
</testsuite>
To pull the Unit Test execution report to show on sonar dashboard. I have used sample git project from here
and below is my sonar-project.properties,
# project metadata (required)
sonar.projectKey=org.codehaus.sonar:javascript-sonar-runner-jstestdriver
sonar.projectName=JavaScript project with Sonar Runner reusing reports generated by JsTestDriver
sonar.projectVersion=1.0
# path to source directories (required)
sonar.sources=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources
# path to tests source directories (required)
sonar.tests=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests
sonar.javascript.jstestdriver.reportsPath=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/target/TEST-Firefox_210_Mac_OS.com.company.BarTest.xml
sonar.sourceEncoding=UTF-8
below is my jsTestDriver.conf
server: http://localhost:9876
load:
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources/*.js
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources/com/company/*.js
test:
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests/*.js
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests/com/company/*.js
plugin:
- name: "coverage"
jar: "coverage-1.3.5.jar"
module: "com.google.jstestdriver.coverage.CoverageModule"
My sonarqube is running on port : 9000 and below is the screen shot. As you see SonarRunner and jsTestDriver just doing a code analysis and not showing any unit tests.
SonarQube doc website says jsTestDriver will run the javascript unit
tests and copy the results in target folder in XML format
SonarQube doesnt run your Unit Tests, it just gathers the reports generated from your manuall run or other tools automatic run (like: Jenkins).
From SonarQube doc:
Prior to the SonarQube analysis, execute your unit tests in order to
generate XML report. The JUnit like XML format supported is the one
generated by js-test-driver
Then I manually created report file in XML format as described, but
still no luck.
If you created manually the report files and reports are still not showing, check your paths if ok.Check if sonar is really reading data from C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/ path
I’m integrating SonarQube in our build system – I installed sonar-runner-2.4 on our build agents and added the sonar-runner.properties for each solution (to the solution’s folder on TFS).
When running the build I’m executing the sonar-runner after the solution has been compiled on the build agent.
Everything seem to work except for the unit test:
On the build’s log I see that almost 200 tests ran and were completed successfully and in the sonar-runner log I see the following:
14:23:29.808 INFO - 583/583 source files analyzed
14:23:30.809 INFO - Sensor org.sonar.plugins.csharp.squid.CSharpSquidSensor#1a50b87 done: 14937 ms
14:23:30.809 INFO - Sensor org.sonar.plugins.csharp.core.CSharpUnitTestResultsProvider$CSharpUnitTestResultsImportSensor#97edbc...
14:23:30.821 INFO - Sensor org.sonar.plugins.csharp.core.CSharpUnitTestResultsProvider$CSharpUnitTestResultsImportSensor#97edbc done: 12 ms
Which seems ok I guess, but when logging into the sonar server it shows that 0 tests ran.
On the sonar-runner.properties file I set the following value to
sonar.cs.vstest.reportsPaths:
sonar.cs.vstest.reportsPaths=TestResults/*.trx
when in this case there are 3 vstest trx files located in the following local path on the build agent: `
D:\sTFS\22965\Sources\TestResults
` (see TestResults.jpg attached).
Attached is the sonar-runner.properties file.
I also attached a screen capture from the sonarqube server (see SonarServer.jpg attached).
Can you please advise what might be the problem?
You should be seeing some messages like:
INFO - Parsing the Visual Studio Test Results file ...
for each unit test result file that is being parsed, see VisualStudioTestResultsFileParser.java#L34
Can you try to pass an absolute path pattern to sonar.cs.vstest.reportsPaths? My guess is that the issue comes from the relative path.
By the way, the use of the sonar-runner to analyze .NET projects is being deprecated. You'll want to have a look at the MSBuild SonarQube Runner that offers very good integration with Team Foundation Server. See the new C# plugin documentation on SonarSource's Wiki: http://docs.sonarqube.org/display/PLUG/C%23+Plugin
EDIT
I just noticed the package name from your logs org.sonar.plugins.csharp.core.CSharpUnitTestResultsProvider. The .core. was present only in outdated versions of the C# plugin (in the 3.x series), and these versions might not support wildcards in report paths. Please upgrade to the latest version.
I used Jacoco eclipse plugin to measure unit test coverage and I was able to export a report using it. I want to integrate that report with sonar so I gave the path to it in the project properties file.
My properties file looks like this
# Required metadata
sonar.projectKey=key
sonar.projectName=name
sonar.projectVersion=1.0
sonar.jacoco.reportPath=jacoco.exec
sonar.tests=junit
sonar.dynamicAnalysis=reuseReports
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportMissing.force.zero=true
# Comma-separated paths to directories with sources (required)
sonar.sources=src
# Comma-separated paths to directories with tests (optional)
sonar.tests=test
# Encoding of the source files
sonar.sourceEncoding=UTF-8
# Language
sonar.language=java
When I executed sonar-runner the following lines were there in the console output
16:23:13.219 INFO - Sensor JaCoCoItSensor...
16:23:13.219 INFO - No JaCoCo analysis of project coverage can be done since there is no class files.
16:23:13.219 INFO - Sensor JaCoCoItSensor done: 0 ms
16:23:13.219 INFO - Sensor JaCoCoOverallSensor...
16:23:13.219 INFO - Sensor JaCoCoOverallSensor done: 0 ms
16:23:13.219 INFO - Sensor JaCoCoSensor...
16:23:13.219 INFO - No JaCoCo analysis of project coverage can be done since there is no class files.
Also the unit test coverage widget indicated "No Data".
Why am I not able to get Sonar to display the coverage results? What is the correct way to do this?
This is my first experience with Jacoco and I'm also new to Sonar, so detailed guides are very much appreciated.
You must specify "sonar.binaries" property that points to the folder where your classes are compiled.