Repository navigation
Add dotnet test coverage scenarios for MSTest (VSTest and MTP) - #348
Conversation
The existing template tests run dotnet test with the default runner on a single .NET target and no coverage. This adds four MSTest scenarios that also collect coverage, so the SDK coverage pipeline is exercised across both runners and both target types in one go: - VSTest, current .NET - VSTest, .NET Framework (net48) - Microsoft.Testing.Platform, current .NET - Microsoft.Testing.Platform, .NET Framework (net48) Projects are generated with dotnet new mstest and its first-class switches (--test-runner, --coverage-tool, --framework), so no csproj editing is needed. Each test asserts a non-empty coverage artifact was produced (*.coverage for VSTest, coverage.cobertura.xml for MTP). The net48 legs only run on Windows, because net48 test apps cannot run on Linux or macOS, so they carry SkipIfPlatform LINUX and OSX traits. MTP mode is opted into with a test.runner entry in global.json, because the VSTest bridge was removed in Microsoft.Testing.Platform 2.x. The helper merges that entry into any existing global.json so an SDK version pin is preserved. Co-authored-by: Copilot App <[email protected]>
The new dotnet test MTP scenarios generate their project with `dotnet new mstest --test-runner Microsoft.Testing.Platform`. That switch opts into MTP by modifying the nearest global.json it finds walking up from the output directory, it does not write one next to the project. In CI the generated projects live under the repo root, so the template rewrote the repo-root global.json and added test.runner=Microsoft.Testing.Platform to it. Every other generated template test (xunit, nunit, mstest, console, webapp, winforms) then failed with "global.json defines test runner to be Microsoft.Testing.Platform. All projects must use that test runner." Write a local global.json in the project directory before running `dotnet new`, so the template modifies that file instead of the shared one. Verified all four coverage tests pass on Windows and that an ancestor global.json placed above the test root is left untouched. Co-authored-by: Copilot App <[email protected]>
|
This PR is causing spurious timeouts in VMR builds on main. Usually the tests complete in 9min but with this change they now sometimes take over 30min and the job times out. I just retried the win-x64 job here: https://dev.azure.com/dnceng/internal/_build/results?buildId=3023050&view=results Please investigate as this is critical. The VMR needs to be close to 100% reliable. |
|
Filed dotnet/dotnet#7757 to track the issue |
|
Ah thanks, I also retried a timed out test step recently but didn't correlate it back to this change. |
|
Do you know which build it was? I could only find 1 that had the problem. |
|
Problem is that I cannot reproduce the hang locally. |
|
Reverting, please let me know if you see timeouts after the revert is propagated to dotnet/dotnet. |
The template tests already run
dotnet test, but only with the default runner, one .NET target, and no coverage. This adds four MSTest scenarios that also collect coverage, so we exercise the SDK coverage pipeline across both runners and both target types in one go:Projects are generated with
dotnet new mstestand its switches (--test-runner,--coverage-tool,--framework), so there is no csproj editing. Each test asserts a non-empty coverage artifact was produced (*.coveragefor VSTest,coverage.cobertura.xmlfor MTP).The net48 legs only run on Windows, because net48 test apps cannot run on Linux or macOS, so they carry
SkipIfPlatformLINUX and OSX traits. MTP mode is opted into with atest.runnerentry in global.json, because the VSTest bridge was removed in Microsoft.Testing.Platform 2.x. The helper merges that entry into any existing global.json so an SDK version pin is preserved.Verified locally on Windows against the repo .NET 11 preview SDK: all 4 pass in about 34s with cold restore included, and a coverage artifact is produced for each. Build is clean with
TreatWarningsAsErrorson.