If a system under test has multiple target frameworks, then
dotnet test /p:CollectCoverage=true
runs multiple coverage runs, overwriting the coverage output each time.
This is the equivalent of AltCover issue #31.
Thanks for reporting this. Will check it out
+1
Same issue here. Due to overwriting its difficult. Work around seems having one project / target framework. But it beat the purpose of multi targeting.
Workaround is just to run dotnet test with -f <framework>, grab the coverage.xml, then run it again with-f <other_framework>
Our workaround is to use merging and two output formats:
/p:CollectCoverage=true /p:CoverletOutput=./TestResults/ /p:CoverletOutputFormat=\"json,cobertura\" /p:MergeWith=./TestResults/coverage.json
I would suggest that the tfm be added to the output file name in this scenario, yielding multiple output files. ReportGenerator or something else can merge them then.
Here's another workaround --
In my Directory.Build.targets file, I have this:
<PropertyGroup>
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
</PropertyGroup>
<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<UseSourceLink>true</UseSourceLink>
<CoverletOutputFormat>cobertura</CoverletOutputFormat>
<Exclude>[xunit.*]*</Exclude>
<CoverletOutput>$(MSBuildThisFileDirectory)coverlet/$(AssemblyName)/$(TargetFramework)/</CoverletOutput>
</PropertyGroup>
It then creates a subdirectory for each assembly and target framework, enabling me to run dotnet test with a wildcard.
Most helpful comment
Our workaround is to use merging and two output formats:
/p:CollectCoverage=true /p:CoverletOutput=./TestResults/ /p:CoverletOutputFormat=\"json,cobertura\" /p:MergeWith=./TestResults/coverage.json