Coverlet: /p:MergeWith is not working

Created on 10 Sep 2019  路  5Comments  路  Source: coverlet-coverage/coverlet

Trying to merge code coverage of two test projects:
steps followed:
1) dotnet add package coverlet.msbuild

2) dotnet add package coverlet.collector

3) Generating code coverage for 1st project:
dotnet test PackService/PackServiceUnitTest/PackServiceUnitTest.csproj --configuration Test -l:trx;LogFileName=UnitTestOutput1.xml /p:CollectCoverage=true /p:CoverletOutput=CoverageResults/

4) Generating code coverage for 2nd project with /p:MergeWith
dotnet test PackService/PackDomainLayerTest/PackDomainLayerTest.csproj --configuration Test -l:trx;LogFileName=UnitTestOutput1.xml /p:CollectCoverage=true /p:CoverletOutput="CoverageResultscoverage" /p:CoverletOutputFormat="json%2copencover" /p:CoverletOutput=CoverageResults/ /p:MergeWith="PackService/PackServiceUnitTest/CoverageResults/coverage.json"

It's generating code coverage reports in json and opencover but is not included with test project 1 code coverage.

Am I missing anything? Any help?

as-designed

All 5 comments

You need to place json file in same folder...you're using relative so will be relative to csproj folder and you're in two different folder PackServiceUnitTest and PackDomainLayerTest try with /p:CoverletOutput=../CoverageResults/ and you can omit json format in last command /p:CoverletOutputFormat="opencover".
You don't need to add coverlet.collector because you're using /p:CollectCoverage(msbuild) and not xplat collector.
I've added full real example try it out https://github.com/tonerdo/coverlet/tree/master/Documentation/Examples/MSBuild/MergeWith

@arohithr8 any news?
Feel free to close if resolved.

@MarcoRossignoli thanks for the response and sorry I didn't find time to work on it,
will try and close it if resolved.

@MarcoRossignoli I made the changes you mentioned and its working. Thank you!!

commands:
dotnet test PackService/PackServiceUnitTest/PackServiceUnitTest.csproj --configuration Test -l:trx;LogFileName=UnitTestOutput1.xml /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/

dotnet test PackService/PackDomainLayerTest/PackDomainLayerTest.csproj --configuration Test -l:trx;LogFileName=UnitTestOutput1.xml /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.json"

Great!Happy coding!

Was this page helpful?
0 / 5 - 0 ratings