I have NET5 xUnit test project. On The build server in CI/CD pipeline I am generating the test coverage report and test execution report with below batch commands. I am using dotnet test to generate reports.
dotnet "C:\sonar-scanner-msbuild-5.5.3.43281-net5.0\SonarScanner.MSBuild.dll" begin /k:"IM" /d:sonar.host.url="myhost.com" /d:sonar.login="xxxxxxx" /d:sonar.cs.opencover.reportsPaths="%WORKSPACE%\Tests\**\TestResults\*\coverage.opencover.xml" /d:sonar.cs.xunit.reportsPaths="%WORKSPACE%\Tests\**\TestResults\TestOutput.xml"
dotnet build "%WORKSPACE%\IM.sln" -nr:false
dotnet test --no-build "%WORKSPACE%\Tests\MyProject1.UnitTests\MyProject.UnitTests.csproj" --logger:trx;LogFileName="%WORKSPACE%\Tests\MyProject1.UnitTests\TestResults\TestOutput.xml" --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
dotnet "C:\sonar-scanner-msbuild-5.5.3.43281-net5.0\SonarScanner.MSBuild.dll" end /d:sonar.login="xxxxxxx"
This creates two reports
...\TestResults\2417ade5-748d-4e44-8129-faa8d64f67b5\coverage.opencover.xml
and
...\TestResults\TestOutput.xml
The scanner was able to import coverage report into SonarQube server.
However scanner is not able to import test execution report. It throws warning
INFO: Sensor C# Unit Test Results Import [csharp]
INFO: Parsing the XUnit Test Results file '...\TestResults\TestOutput.xml'.
WARN: Could not import unit test report '...\TestResults\TestOutput.xml'
I verified the TestOutput.xml file exists at the given location
Related
I'm having a problem with the Sonarqube report. It is showing 42.5% for test coverage, but "-" Unit Tests.
I created the report with coverage.py and with the command
coverage run --branch --omit 'venv/*,tests/*' -m unittest.
I've set up my coverage path with the following line:
sonar.python.coverage.reportPaths=coverage.xml
I couldn't find a solution online and don't know if it's a problem while generating the report or importing it to Sonarqube. Here is a picture of the report:
Thanks in advance!
Since Sonarqube doesn't support ruby test execution report by default, i need a way to manually generate the generic test execution report that Sonarqube will accept, on my local machine during execution of the rspec unit tests. The xml report can be given as input during the execution of sonar-scanner .
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 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
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