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?
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!