Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet-coverage No code coverage data available. Profiler was not initialized

I am trying to collect my code coverage for my .net core 6 project, I have written some tests and I am planning to upload the results to sonarqube.

I read this documentation and decided to go with the dotnet-coverage tool, for some reason I can't get the code coverage, running the command

dotnet tool run dotnet-coverage collect 'dotnet test' -f xml -o 'tests/TestResults/coverage.xml'

gives me the following message No code coverage data available. Profiler was not initialized. and creates an empty coverage.xml file, I am using a macos with m1 processor, not sure if that makes any difference.

I am aware of other ways of generating code coverage but I am curious as to what that message means.

like image 669
MoTahir Avatar asked Apr 05 '26 15:04

MoTahir


2 Answers

I was able to run the command from the question on windows but I needed to add the following to my steps to be able to run it successfully in a Linux environment.

apt-get update && apt-get install libxml2
like image 141
Christo Nel Avatar answered Apr 08 '26 07:04

Christo Nel


It works perfectly for me. just few changes.

I ran cmd:

dotnet-coverage collect dotnet test -f xml -o coverage.xml

enter image description here

and it is also uploaded to sonarqube

like image 43
CodingMytra Avatar answered Apr 08 '26 07:04

CodingMytra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!