I need to publish my test coverage results into SonarCloud. My current pipeline is this
Update: - In run code analysis step this log can be found. But in SonarCloud coverage result is not displayed.
INFO: Parsing the Visual Studio coverage XML report D:\a\1\.\TestResults\VssAdministrator_fv-az185_2019-11-13_11_15_46\In\fv-az185\VssAdministrator_fv-az185 2019-11-13 11_15_34.coveragexml
INFO: Adding this code coverage report to the cache for later reuse: D:\a\1\.\TestResults\VssAdministrator_fv-az185_2019-11-13_11_15_46\In\fv-az185\VssAdministrator_fv-az185 2019-11-13 11_15_34.coveragexml
INFO: Coverage Report Statistics: 21 files, 20 main files, 20 main files with coverage, 1 test files, 0 project excluded files, 0 other language files.
How to publish azure pipeline test result to SonarCloud
According to the document:
From Team Foundation Server 2015 or Visual Studio Team Services
Optional: To import code coverage into SonarQube, add the Visual Studio Test build task after the build one and tick Code Coverage
Enabled
So, make sure you have checked Code coverage enabled in the VsTest task.
Besides, if you already checked that option, you can check if the version of your SonarQube is 6.5, there is an issue on that version:
SonarQube 6.5 – Code Coverage Result is not displayed
And, if you can get the Code Coverage in Azure devops but not in SonarCloud, check if this thread give any helps.
Hope this helps.
https://medium.com/#chameeradulanga87/running-asp-net-nunit-tests-in-azure-devops-build-pipeline-and-publishing-results-to-sonar-cloud-20d14dccf275
Complete Guide to publishing test results
Related
Hi guys i have a problem with my code coverage of my azure pipeline. When the CI gets trigged for the master branch the agent has a job to test the .net core. When i use this test i have to configure the route and also enable the code coverage. After the CI has been done it ended succesfully and i can download a file with the code coverage. The problem i have is i cant open this file, not with visual studio or anything else. Aynone that knows how i can fix this problem and maby i didnt configure it right?
Picture of my settings:
picture of the file
picture of the error https://i.stack.imgur.com/fxqdI.png
Seems you are using the wrong configuration. I'm afraid --collect"Code coverage" will not work.
You could add a .NET core test task and add /p:CollectCoverage=true argument then use report generate task for adding code coverage reports.
More detail steps, please refer below tutorials:
ASP.NET Core code coverage reports on Azure DevOps
Azure DevOps, unit testing and code coverage with .Net Core
To generate code coverage please follow this steps
Restore nuget packages
Build the app
Run unit tests (You need to add nuegte package to test projects -> coverlet.collector to use 'XPlat Code Coverage')
Install report generator
Run report generator
Publish code coverage
I am using the ReportGenerator task in my Azure DevOps build to generate a code coverage report. The problem is that the generated report is empty.
In my VsTest task that runs the unit tests I have checked the option Code coverage enabled. The .coverage file is correctly generated and the unit tests are all successfully run. However, the generated code coverage report shows that no code was covered by any of the unit tests.
Here is a screenshot of my code coverage Report Generator task.
And here is the output from the code coverage report.
Here is a screenshot of the Azure DevOps log file for the task showing that it executed correctly without any errors.
Interestingly the log does show the following
Analyzing 0 classes
Is this because ReportGenerator cannnot find the assemblies / classes? I've tried specififying a value for Source directories but this has made no difference.
Why is the code coverage report showing no code coverage?
ReportGenerator can not handle .coverage files.
You can find the supported formats here: https://github.com/danielpalme/ReportGenerator#supported-input-and-output-file-formats
You can use a tool like OpenCover or coverlet to generate a coverage report in a format that ReportGenerator is able to parse.
Or you can convert the .coverage file format. Here you find instructions how this can be done: https://github.com/danielpalme/ReportGenerator/wiki/Visual-Studio-Coverage-Tools
I'am trying to create a build pipeline in Azure DevOps which contain a "vs test task". Nothing fancy here. I want to get the code coverage to send it to sonaQube. However, after the pipeline went through the task there is not .Coverage file created.
There is some errors that might be the issue but i'm not sure.
there is a big "Data collection : Could not find data collector 'Code Coverage'", This might be related to the fact that my UnitTestProject.dll is built for Framework 4.6.2 and Platform AnyCPU(for this issue I tried to forced: otherConsoleOptions:/Framework:NETFramework,Version=v4.6.2').
My agent is running on Windows server 2012 and Visual Studio Enterprise everything is up to date:
VS version
[command]"C:\Program Files (x86)\Microsoft VisualStudio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" #C:\Agent_AzureDevOps_1_work_temp\22f8bb11-e53e-11e9-95d5-5bdab8c29281.txt
Microsoft (R) Test Execution Command Line Tool Version 15.9.0
My .trx file is created, however, my .coverage file is nowhere to be seen.
I made sure Code Coverage was Enabled.
My package contain those NuGet
NuGet in my package.config
I'am blocked and don't know where to look anymore if you guys have an idea.
Thanks for the time. If you guys want more information don't hesitate to ask.
I do not have enough reputation to add a comment, so I hope this post will not be deleted (although it is not a direct answer, I think). I wanted to suggest you the following:
Do you have an own *.runsettings file (where you might have specified a specific entry? If you do not specify a *.runsettings file by yourself, the Azure DevOps vstest#2 Task will use a "default" runsettings file. At least this is what I could observe in the log (debug=true)
Hope this helps
BR Michael
I have a similar problem. I run this command :
>dotnet test --logger trx "--collect:Code Coverage"
Determining projects to restore...
All projects are up-to-date for restore.
MyAPI -> ...\MyApi\bin\Debug\net47\MyAPI.exe
MyAPI.Tests -> ...\MyAPI.Tests\bin\Debug\net47\MyAPI.Tests.dll
Warning: Update the Microsoft.NET.Test.Sdk package reference to version 15.8.0 or later to collect code coverage.
Test run for ...\MyAPI.Tests\bin\Debug\net47\MyAPI.Tests.dll (.NETFramework,Version=v4.7)
Microsoft (R) Test Execution Command Line Tool Version 16.10.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Data collection : Unable to find a datacollector with friendly name 'Code Coverage'.
Data collection : Could not find data collector 'Code Coverage'
Results File: ...\MyAPI.Tests\TestResults\***_2021-09-03_12_02_21.trx
Passed! - Failed: 0, Passed: 22, Skipped: 0, Total: 22, Duration: 201 ms - MyAPI.Tests.dll (net47)
The .trx is generated, but not the .coverage.
The solution is to add the NuGet package Microsoft.NET.Test.Sdk in the test project.
My team uses VSTS with hosted agents and a Visual Studio Test build task to run all tests and produce code coverage. However the tab Code coverage remains empty afterwards, only showing a link to download the *.coverage file.
I actually expect the code coverage results to be shown, with tables and graphs which projects are tested and it's respective coverage.
We are using the Visual Studio Test build task to test net461 assemblies with the Code Coverage enabled checked.
Somewhat related are both this and this issue, but not entirely, because we are just using MSTest Framework with built-in Visual Studio Test build task, which (I understand) should also automatically publish the code coverage results.
Am I missing something to get this Code coverage view working? Thanks!!
In Code coverage Tab, you need to use Publish Code Coverage Results task to show tables and graphs there.
While for Publish Code Coverage Results task, it only supports Code Coverage data in Jacoco or Cobertura formats. So the result of the *.coverage file can not be shown by tables and graphs in Code coverage Tab.
More details, you can refer the blog Browse Code Coverage reports and the issue How to publish the code coverage result with a .coverage file.
I have a CakeBuild build script which compiles a Visual Studio 2015 solution then uses the Cake add in for NUnit 3 to run the unit tests and generate the TestResult.xml file. The tests pass successfully when run locally and the report is generated.
This same build script is being run by TeamCity (version 10.0.2), with the build agent also successfully running the tests (all passing) and the TestReport.xml file being generated.
The TeamCity build configuration has been configured via the XML Report Processing Build Feature to import the NUnit report. The build log suggests this has also occurred successfully. Example of the log:
[10:06:41]NUnit report watcher
[10:06:41][NUnit report watcher] 1 report found for paths:
[10:06:41][NUnit report watcher] **/TestResult.xml
[10:06:41][NUnit report watcher] Successfully parsed
[10:06:41][Successfully parsed] 1 report
[10:06:41][Successfully parsed] build\TestResult.xml
However, there is no reference to any of the tests in the build run - the Test tab is missing completely and no other references to the tests at all.
Is there anything else that needs to be configured to get the test results to show up?
We've had the same issue and found the solution in https://github.com/nunit/teamcity-event-listener/issues/39
Main point is to make sure to include the package NUnit.Extension.TeamCityEventListener which reports the results to TeamCity.
In addition the Nunit Runner Settings should include
NUnit3(path, new NUnit3Settings {
TeamCity = true
});