Description
This is in regard to the automatic merging of coverage files when tests are run at the solution-level, as described in https://devblogs.microsoft.com/dotnet/whats-new-in-our-code-coverage-tooling/
Auto-Merge for solutions
Running dotnet test --collect "Code Coverage" at the solution level now automatically merges code coverage for all your test projects. Visit Scenario 24 Code coverage for solution to see full example.
I pulled the referenced repo with sample code, and while the project-level coverage files were merged into a single file, the project/folder where the file was saved differed between test runs.
dotnet test --collect "Code Coverage"
Microsoft (R) Test Execution Command Line Tool Version 17.5.0 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 4, Skipped: 0, Total: 4, Duration: 7 ms - Calculator.Core.Tests.dll (net7.0)
Passed! - Failed: 0, Passed: 4, Skipped: 0, Total: 4, Duration: 512 ms - Calculator.Console.Tests.dll (net7.0)
Passed! - Failed: 0, Passed: 4, Skipped: 0, Total: 4, Duration: 8 ms - Calculator.Server.Tests.dll (net7.0)
Skipped TestOperations("/subtract/3/5","-2") [4 s]
Skipped TestOperations("/add/3/5","8") [4 s]
Skipped TestOperations("/multiply/3/5","15") [4 s]
Skipped TestOperations("/divide/35/5","7") [4 s]
Skipped! - Failed: 0, Passed: 0, Skipped: 4, Total: 4, Duration: 4 s - Calculator.Server.IntegrationTests.dll (net7.0)
Attachments:
C:\Users\MyUser\codecoverage\samples\Calculator\tests\Calculator.Server.IntegrationTests\TestResults\ab55596d-baa4-4bb2-9038-16634355968f\MyUser_2024-01-01.16_44_54.coverage
2nd execution
dotnet test --collect "Code Coverage"
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 4, Skipped: 0, Total: 4, Duration: 7 ms - Calculator.Core.Tests.dll (net7.0)
Passed! - Failed: 0, Passed: 4, Skipped: 0, Total: 4, Duration: 505 ms - Calculator.Console.Tests.dll (net7.0)
Passed! - Failed: 0, Passed: 4, Skipped: 0, Total: 4, Duration: 11 ms - Calculator.Server.Tests.dll (net7.0)
Skipped TestOperations("/add/3/5","8") [4 s]
Skipped TestOperations("/subtract/3/5","-2") [4 s]
Skipped TestOperations("/multiply/3/5","15") [4 s]
Skipped TestOperations("/divide/35/5","7") [4 s]
Skipped! - Failed: 0, Passed: 0, Skipped: 4, Total: 4, Duration: 4 s - Calculator.Server.IntegrationTests.dll (net7.0)
Attachments:
C:\Users\MyUser\codecoverage\samples\Calculator\tests\Calculator.Core.Tests\TestResults\e18df044-bf6a-47a2-a739-e7d0e8a6443f\MyUser_2024-01-01.16_45_46.coverage
As the results show, the coverage of the first run was saved within the Calculator.Server.IntegrationTests\TestResults
folder, while the file for the 2nd execution was saved in Calculator.Core.Tests\TestResults
I would expect a solution wide file to be saved in the solution root, or under a TestResults
folder in the sln root by default. I can still manually merge with the dotnet-coverage
tool, but I was excited at the prospect of not needing the extra steps.
I am running dotnet 7.0.203 on Windows 11. I get the same results with and without the dotnet-coverage
tool installed. I am developing in VS Code, but don't believe that is relevant because all of the code samples are from the command line.