TeamCity failing to import DotCover report - teamcity

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']"

Related

SonarQuve Could not import unit test report for xUnit

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

Sonarqube shows Coverage percentage but no unit tests

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!

Sonarqube coverage 0% in react js

I have written some unit tests in jest. All of them are successful. Able to view test coverage report generated by jest
But my sonarqube dashboard always shows 0% on coverage but unit tests are being detected.
I am using jest-sonar-reporter for sonar consumable format generation of reports.
This is my sonar properties file
sonar.projectKey=skyflow-app
sonar.projectName=Skyflow App
sonar.host.url = http://localhost:9000
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.exclusions=**/node_modules/**,**/*.spec.ts, **/*.stories.tsx
sonar.tests=src
sonar.test.inclusions=**/*.test.tsx,**/*.test.ts
sonar.test.exclusions=**/*.stories.tsx
sonar.ts.tslintconfigpath=tslint.json
sonar.testExecutionReportPaths=testResults/sonar-report.xml
# sonar.coverageReportPaths = coverage/lcov.info
sonar.javascript.lcov.reportPaths = coverage/lcov.info
Please let me know where i am going wrong.
A dumb mistake from myside.
Replacing sonar.javascript.lcov.reportPaths with
sonar.typescript.lcov.reportPaths solved the issue.
can you share console output of the jenkins job?
in my case, jenkins cannot find the coverage report and got log in console output like this :
15:26:37 [ERROR] Coverage report '/home/jenkins/workspace/microservices-pipelines/xxx/target/jacoco.exec' could not be read/imported. Error: {}
15:26:37 java.lang.IllegalStateException: Failed to parse JaCoCo XML report: /home/jenkins/workspace/microservices-pipelines/xxx/target/jacoco.exec

NUnit results not showing up in SonarQube after import

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

TeamCity dotCover report path for Sonar

I'm trying to integrate the sonar analysis into by TeamCity build process. I have a NUnit build step which runs my unit tests and then runs dotCover for the coverage.
My next step is the sonar-runner. The configuration that currently exists is; gallio.mode=dotCover, sonar.gallio.mode=reuseReport but I also need sonar.gallio.reports.path.
Does anybody know the path to the dotCover report generated in the the previous step?
Spent some amount of time on the same issue, but with newer Sonar c# plugin (v.2.3) - Gallio support has been dropped, but the report is still required.
To answer the question directly, TeamCity puts dotcover snapshot file into a temp folder with a name like coverage_dotcover27574681205420364801.data (where digits are random). So
The procedure is:
Create a PowerShell Build step in Team City after the step with test and coverage
you may use Command line if you prefer
Get the full dotCover snapshot name in temp folder
Run dotCover to produce a HTML report from a snapshot
Note - Sonar (c# plugin v 2.3) supports only dotCover HTML reports
Pass the produced HTML report to sonar
PowerShell script:
$snapshot = Get-ChildItem "%system.teamcity.build.tempDir%" `
-Filter coverage_dotcover*.data `
| select -ExpandProperty FullName -First 1
%teamcity.dotCover.home%\dotCover.exe report `
/ReportType=HTML /Source="$snapshot" `
/Output="%sonar.coverageReport%"
Now you can specify your report in sonnar runner as sonar.cs.dotcover.reportsPaths='%sonar.coverageReport%'
Where %sonar.coverageReport% is a defined property in a TeamCity
It seems TeamCity 2017 no longer creates coverage_dotcover*.data files. Instead it creates *.dcvr files.
There are potentially multiple files which need to be merged before you can create the report. As a result the powershell need updating.
So using the steps provided by Oleksandr, just update the script to be:
$snapshotfiles = Get-ChildItem "%system.teamcity.build.tempDir%" `
-recurse -Filter *.dcvr `
| select -ExpandProperty Name
$snapshots = $snapshotfiles -join ";"
%teamcity.dotCover.home%\dotCover.exe merge /Source=$snapshots
/Output=dotcovermerge.dcvr
%teamcity.dotCover.home%\dotCover.exe report `
/ReportType=HTML /Source=dotcovermerge.dcvr `
/Output="%sonar.coverageReport%"
Then the property %sonar.coverageReport% can be passed to the sonarqube scanner. Btw, you need to create a parameter in TC for %sonar.coverageReport% e.g. "sonarcoverage.html"
I couldn't find a way to do this using the built in NUnit runner. I managed to get it working by using a powershell build step to manually call the required commands.
First step is to run the NUnit tests via Gallio within a dotCover cover call:
& dotCover cover `
/TargetExecutable="C:\Program Files\Gallio\bin\Gallio.Echo.exe" `
/TargetArguments="/report-type:XML /report-name-format:test-report /runner:IsolatedProcess /report-directory:.\Gallio .\Path\Test.dll" `
/Filters="+:WhatToCover" `
/Output=coverage.snapshot
The Gallio test report is then available to be picked up by Sonar with reuseReport, TeamCity automatically detects the test results.
You can make TeamCity directly process the coverage snapshot by writing a service message to standard output:
Write-Host "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='coverage.snapshot']"
To get the coverage info into a format usable by Sonar you need to use the dotCover report command and the undocumented report type TeamCityXML:
& dotCover report /Source=coverage.snapshot /Output=coverage-report.xml /ReportType=TeamCityXML
We are using SonarScanner for MSBuild and needed to add the team city temporary build path to the begin step.
Run the SonarScanner.MSBuild.exe begin command, specifying the temp build directory to be where the reports will be available using
/d:sonar.cs.dotcover.reportsPaths="%system.teamcity.build.tempDir%".
Build your project using MSBuild
Run your test tool, instructing it to produce a report at the same location specified earlier to the MSBuild SonarQube Runner
Run the SonarScanner.MSBuild.exe end command
The coverage report from the nunit/dotcover build step is stored in the teamcity hidden artifacts directory. You need to add that as an artifact dependency in the sonar step. I wouldn't recommend the hidden artifact route but it can be done.
This is the artifact path I used to publish the report which worked for a few weeks then began to fail:
%env.TEAMCITY_DATA_PATH%/system\artifacts\**\%teamcity.build.id%\.teamcity\.NETCoverage\dotCover.snapshot
Once you have the report, your're home free though.
Although it might be a bit cumbersome solution, I'm using two chained builds.
The first build configuration builds the solution and runs the tests/coverage, plus saves the dotCover snapshot as an artifact.
The other build has an artifact dependency on the first one on .teamcity/.NETCoverage/dotCover.snapshot and runs
"C:\Program Files (x86)\JetBrains\dotCover\v2.7\bin\dotCover.exe" report /ReportType=HTML /Source="dotCover.snapshot" /Output="dotCover.html" and, as the latest step, executes SonarRunner (your project properties file will point to the "dotCover.html").
(Tried with SonarQube 5, dotCover 2.7, TC8)
Below is what worked for me. I am on TC 2018.2.4 and the bundled version of the dotCover was not generating anything so I upgraded that to the latest version as well which is 2019.1.1
I could not make the agent use the latest version of the dotcover tools so I had to construct the folder path for that rather than using the default %teamcity.dotCover.home% variable.
I also did not want to use the temp folder as things were getting deleted there by the build.
$snapshot_file_list = Get-ChildItem "%system.teamcity.build.tempDir%" -recurse -Filter coverage_dotcover*.data | select -ExpandProperty FullName
Echo "dotCover Snapshot files"
Echo $snapshot_file_list
$joined_snapshot_files = $snapshot_file_list -join ";"
Echo "Merging data files to %system.teamcity.build.checkoutDir%\dotcovermerge.dcvr"
& "%teamcity.agent.tools.dir%\JetBrains.dotCover.CommandLineTools.2019.1.1\dotCover.exe" merge /Source=$joined_snapshot_files /Output="%system.teamcity.build.checkoutDir%\dotcovermerge.dcvr" /LogFile="%system.teamcity.build.checkoutDir%\dotCover.log"
Echo "Generating dotCover Html report"
Echo "%system.teamcity.build.checkoutDir%\%sonar.coverageReport%"
& "%teamcity.agent.tools.dir%\JetBrains.dotCover.CommandLineTools.2019.1.1\dotCover.exe" report /ReportType=HTML /Source="%system.teamcity.build.checkoutDir%\dotcovermerge.dcvr" /Output="%system.teamcity.build.checkoutDir%\%sonar.coverageReport%"

Resources