You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Upgrade from MSTest from 3.7.3> has 'Code Coverage' issues #185
With MSTest package versions above 3.7.3 (Current version is 3.10.0), I’m unable to collect code coverage data using dotnet test in Azure DevOps pipelines with a Windows container image.
I receive the following message from the Dotnet test task: "Data collector 'Code Coverage' message: No code coverage data available. Profiler was not initialized."
I also tried using coverlet, but that didn’t work either and still shows 0% coverage.
Could you advise on a solution or suggest next steps?
Expected behavior
Code coverage tab should show the details as it was showing with MSTest 3.7.3
Prashanth Narasimha Murthy (@prashanthnmurthy) I would suggest to run dotnet test locally and see if you observe the same results or not. Can you check that Microsoft.CodeCoverage is part of the test project?
The packages Microsoft.Testing.Extensions.CodeCoverage and Microsoft.Testing.Extensions.TrxReport are only relevant for Microsoft.Testing.Platform. It seems that you are using VSTest and didn't migrate to Microsoft.Testing.Platform, so it's expected that Microsoft.Testing.Extensions.CodeCoverage, Microsoft.Testing.Extensions.TrxReport don't work.
Youssef Fahmy (@Youssef1313) Is it necessary to migrate to Microsoft.Testing.Platform, or are there alternative ways to obtain code coverage with MSTest/VSTest?
I see that you have 4 test projects, however no tests were executed for 3 projects.
Code coverage collector will give this warning when no clients are connected, and hence it will generate an empty report => "No code coverage data available. Profiler was not initialized"
2 tests were executed, and a coverage report is generated at the end. Can you please check if the coverage report contains the right data? Or is it empty?
MSTest Version 3.10.0
1.2. dotnet test => coverage is not generated
1.2. vstest.console.exe (17.14) => coverage is generated correctly
MSTest Version 3.7.3
2.1. dotnet test => coverage is generated correctly
2.2. vstest.console.exe (17.14) => coverage is generated correctly
Both versions of MSTest uses the same MS.CC 17.14.1 reference. I believe that there are some changes on MSTest side that does not work with dotnet test. Running the same project with vstest.console.exe generated correct coverage report.
I cannot imagine how MSTest itself can have an impact on this and why dotnet test is different from vstest.console.exe.
Is there anything specific you can point out to? VSTest simply just calls MSTest to run tests via ITestExecutor. I don't see any interactions with CC 😕
Is there a different behavior with regards to running the tests with the MSTest upgrade?
I cannot imagine how MSTest itself can have an impact on this and why dotnet test is different from vstest.console.exe.
Is there anything specific you can point out to? VSTest simply just calls MSTest to run tests via ITestExecutor. I don't see any interactions with CC 😕
Is there a different behavior with regards to running the tests with the MSTest upgrade?
Jakub Jareš (@nohwnd) The solution is not working for me, and as you have suggested I need to discuss with my FTE to provide the source project access and package sources access.
Workaround: User is using dotnet test and vstest. In this case Microsoft.Testing.Extensions.CodeCoverage libs are not required in the test bin folder. These can be adding the following reference in the test project.
Jakub Jareš (@nohwnd)Youssef Fahmy (@Youssef1313) The issue happens when using dotnet test and test bin folder has a file with *Collector.dll in it. vstest considers this folder for loading data collectors because of *Collector.dll in it. datacollector loads Microsoft.CodeCoverage.Core.dll from the bin folder instead of the original location (Microsoft.CodeCoverage package?). Microsoft.CodeCoverage.Core.dll sets env var according to its location on the disk and this does not work as MTP.Extension.CC has a different folder structure than MS.CC.
I was working on the solution that Microsoft.CodeCoverage.Core.dll sets env var if it is in the bin folder. This has some issues.
MTP.Extension.CC doesnt ship all the files that are shipped with MS.CC. We can add these missing files in MTP.Extension.CC but it doesn't make sense as these are never used by MTP itself.
Microsoft.NET.Test.Sdk/Microsoft.TestPlatform/MS.CC are built using the same source code. While MTP.Extension.CC could target to a different source code which are not compatible with TestSDK/MS.CC. In that case, we need to create some compatibility matrix, and user has to ensure that correct versions are used.
I think the simplest solution is that datacollector loads code coverage libraries from MS.CC package and not test bin folder. This will ensure that dotnet test / vstest loads correct code coverage libraries with the right version. Thoughts?
There is another scenario. Test project is using MSTest 3.7.3 (no MTP.CC stuff in the test bin folder). But has a reference of Microsoft.CodeCoverage.Core package. And because of this now test bin folder has Microsoft.CodeCoverage.Core.dll and no other code coverage stuff. Datacollector will load it from the bin folder again. And we have no way of providing right env vars in this case.
Activity
Youssef1313 commentedon Aug 1, 2025
Thanks for reporting this Prashanth Narasimha Murthy (@prashanthnmurthy)
I'm moving to microsoft/codecoverage for further investigation on CC side.
fhnaseer commentedon Aug 1, 2025
Prashanth Narasimha Murthy (@prashanthnmurthy) I would suggest to run dotnet test locally and see if you observe the same results or not. Can you check that Microsoft.CodeCoverage is part of the test project?
prashanthnmurthy commentedon Aug 1, 2025
fhnaseer Yes, I had the Microsoft.CodeCoverage as part of the test project, I also verified again locally with the same error.
Commands I used:
dotnet test dirs.proj --no-restore --no-build
fhnaseer commentedon Aug 4, 2025
Where do you specify collect code coverage? Any runsettings?
Also, can you please try
dotnet test --no-build --collect "Code Coverage" --diag log.dotnet.txt? And share these logs?prashanthnmurthy commentedon Aug 4, 2025
We use a runsettings file. Below is the run settings file.
CodeCoverage.zip
I executed the command above, and the log files can be found here.
log.dotnet.zip
I also added another assembly, Microsoft.Testing.Extensions.CodeCoverage, Microsoft.Testing.Extensions.TrxReport but it isn't functioning as expected.
Youssef1313 commentedon Aug 5, 2025
The packages Microsoft.Testing.Extensions.CodeCoverage and Microsoft.Testing.Extensions.TrxReport are only relevant for Microsoft.Testing.Platform. It seems that you are using VSTest and didn't migrate to Microsoft.Testing.Platform, so it's expected that Microsoft.Testing.Extensions.CodeCoverage, Microsoft.Testing.Extensions.TrxReport don't work.
prashanthnmurthy commentedon Aug 5, 2025
Youssef Fahmy (@Youssef1313) Is it necessary to migrate to Microsoft.Testing.Platform, or are there alternative ways to obtain code coverage with MSTest/VSTest?
Youssef1313 commentedon Aug 5, 2025
While the migration is generally recommended, it should still be possible to obtain code coverage using MSTest with VSTest.
fhnaseer commentedon Aug 5, 2025
I see that you have 4 test projects, however no tests were executed for 3 projects.
Code coverage collector will give this warning when no clients are connected, and hence it will generate an empty report => "No code coverage data available. Profiler was not initialized"
2 tests were executed, and a coverage report is generated at the end. Can you please check if the coverage report contains the right data? Or is it empty?
fhnaseer commentedon Aug 5, 2025
Youssef Fahmy (@Youssef1313) We tried running the following workflows
1.2. dotnet test => coverage is not generated
1.2. vstest.console.exe (17.14) => coverage is generated correctly
2.1. dotnet test => coverage is generated correctly
2.2. vstest.console.exe (17.14) => coverage is generated correctly
Both versions of MSTest uses the same MS.CC 17.14.1 reference. I believe that there are some changes on MSTest side that does not work with
dotnet test. Running the same project withvstest.console.exegenerated correct coverage report.Youssef1313 commentedon Aug 5, 2025
I cannot imagine how MSTest itself can have an impact on this and why
dotnet testis different fromvstest.console.exe.Is there anything specific you can point out to? VSTest simply just calls MSTest to run tests via
ITestExecutor. I don't see any interactions with CC 😕Is there a different behavior with regards to running the tests with the MSTest upgrade?
fhnaseer commentedon Aug 5, 2025
Maybe Jakub Jareš (@nohwnd) can help in figuring this out.
nohwnd commentedon Aug 7, 2025
This works for me:
nohwnd commentedon Aug 7, 2025
Prashanth Narasimha Murthy (@prashanthnmurthy) will need a repro for this one. Reach out to me on internal teams if you cannot share more stuff publicly.
prashanthnmurthy commentedon Aug 7, 2025
Jakub Jareš (@nohwnd) The solution is not working for me, and as you have suggested I need to discuss with my FTE to provide the source project access and package sources access.
fhnaseer commentedon Aug 25, 2025
Workaround: User is using
dotnet testandvstest. In this case Microsoft.Testing.Extensions.CodeCoverage libs are not required in the test bin folder. These can be adding the following reference in the test project.<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.14.2" ExcludeAssets="all" />fhnaseer commentedon Aug 25, 2025
Jakub Jareš (@nohwnd) Youssef Fahmy (@Youssef1313) The issue happens when using dotnet test and test bin folder has a file with
*Collector.dllin it.vstestconsiders this folder for loading data collectors because of*Collector.dllin it. datacollector loadsMicrosoft.CodeCoverage.Core.dllfrom the bin folder instead of the original location (Microsoft.CodeCoverage package?).Microsoft.CodeCoverage.Core.dllsets env var according to its location on the disk and this does not work as MTP.Extension.CC has a different folder structure than MS.CC.I was working on the solution that
Microsoft.CodeCoverage.Core.dllsets env var if it is in the bin folder. This has some issues.MTP.Extension.CC doesnt ship all the files that are shipped with MS.CC. We can add these missing files in MTP.Extension.CC but it doesn't make sense as these are never used by MTP itself.
Microsoft.NET.Test.Sdk/Microsoft.TestPlatform/MS.CC are built using the same source code. While MTP.Extension.CC could target to a different source code which are not compatible with TestSDK/MS.CC. In that case, we need to create some compatibility matrix, and user has to ensure that correct versions are used.
I think the simplest solution is that datacollector loads code coverage libraries from MS.CC package and not test bin folder. This will ensure that dotnet test / vstest loads correct code coverage libraries with the right version. Thoughts?
Youssef1313 commentedon Aug 25, 2025
What necessary files are missing?
fhnaseer commentedon Aug 25, 2025
CodeCoverage.exe, Microsoft.DisSymReader.dll.
There is another scenario. Test project is using
MSTest 3.7.3(no MTP.CC stuff in the test bin folder). But has a reference ofMicrosoft.CodeCoverage.Corepackage. And because of this now test bin folder hasMicrosoft.CodeCoverage.Core.dlland no other code coverage stuff.Datacollectorwill load it from the bin folder again. And we have no way of providing right env vars in this case.chrisoldwood commentedon Oct 28, 2026
(I got here by searching for
No code coverage data available. Profiler was not initialized.)I ran across this issue after consolidating some packages in a test project and found that switching to the meta package
MSTest, i.e.caused code coverage under Azure DevOps to suddenly go missing.
After reading the comments I guessed that I needed to revert to specifying these two packages explicitly again:
(I had already worked that out by reverting my changes one-by-one but I wanted to see if this was a known issue or a red herring.)