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

3

8

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.

Resistive answered 9/8, 2022 at 23:6 Comment(2)
do you get this error along with sonarqube setup or while running as a standalone cmd ?Eberly
I am running sonarqube with docker compose and using dotnet sonarqube scanner toolResistive
E
2

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

Eberly answered 12/8, 2022 at 5:41 Comment(2)
Doesn't work for me. Are you using a Mac M1 processor? I get the same issue as the OP and can't seem to resolve it.Hydrastine
No I used windowsEberly
W
2

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
Walterwalters answered 8/5, 2023 at 10:17 Comment(0)
R
0

I just ran into the same issue on GitHub Actions pipeline. In order to resolve this I had to add installation of the following packages prior to running the analysis, which fixed it for me:

- name: Install dependencies
    run: apt-get update && apt-get install -y libxrender1 libfontconfig libxext6 libc6 libxml2

Please note that we run our pipelines on Debian, so your package names may vary if you run on a different OS flavor

Relativity answered 15/11, 2022 at 18:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.