Closed StefH closed 4 months ago
dotnet test ./MyTest.csproj --no-build --configuration Release --results-directory TestResults --logger trx --collect "XPlat Code Coverage;Format=cobertura"
You are running tests with coverlet coverage collector ("XPlat Code Coverage") and not Microsoft Code Coverage collector. Try running without specifying --collect
to dotnet test
.
This yields the same warning and the coverageFile.xml is empty.
Can you run with logs and share these? dotnet-coverage collect "dotnet test test.dll" -l log.txt -ll Verbose
From the logs, your dll is being skipped. Do you have some additional include/exclude in the runsettings file? Is it also possible that your dll is skipped because it contains reserved names which are skipped automatically.
2024-07-26 15:25:32.104 +02:00 [INF] LoggerBase.LoadModuleData[0]: Loading module id:C:...\bin\Release\net6.0\win-x86....dll_0_0, path:C:*\bin\Release\net6.0\win-x86*.dll 2024-07-26 15:25:32.104 +02:00 [INF] ReportGenerator.LoadModule: name:C:....\bin\Release\net6.0\win-x86....dll, skipReason:path_is_excluded, detailed reason: 2024-07-26 15:25:32.104 +02:00 [INF] StaticStreamCreator.CreateStream: Creating SharedMemoryStream. streamId:84, identifier:28a32265-7278-49cb-93ab-ea2470161bd9, bufferName:CodeCoverage.16cd45d7-cdc5-4ae7-a576-da8a0189acc0.d28a32265-7278-49cb-93ab-ea2470161bd9, bufferSize:6 2024-07-26 15:25:32.104 +02:00 [VRB] LoggerBase.OnDynamicInstrumentationSkipped: path:C:....\bin\Release\net6.0\win-x86....dll, reason:path_is_excluded, isManaged:True
@fhnaseer Good catch ! Thank you.
The other .NET48 projects where an exe
, so I used these settings in the config file:
<ModulePaths>
<Include>
<ModulePath>.*MyCompanyName.*\.exe$</ModulePath>
</Include>
</ModulePaths>
But apparently, although an exe should be generated, for this .NET 6 project I need to include the dll.
After changing the settings file, it works correct.
Include/Exclude are regular expressions. You can also use <ModulePath>.*MyCompany\.[^/\\]+\.(dll|exe)$</ModulePath>
or only company name and ignore extension.
When running this command in a powershell script:
I get a warning:
No code coverage data available. Profiler was not initialized.
and indeed the coverageFile.xml is empty:Note that both the project and the testproject are a net6.0 project with RuntimeIdentifier win-x86.
And using a net48 project + test project works fine.