Skip to content

Add dotnet test coverage scenarios for MSTest (VSTest and MTP) - #348

Merged
akoeplinger merged 2 commits into
dotnet:mainfrom
nohwnd:nohwnd-dotnet-test-scenarios
Jul 14, 2026
Merged

akoeplinger merged 2 commits into
dotnet:mainfrom
nohwnd:nohwnd-dotnet-test-scenarios

Conversation

@nohwnd

@nohwnd nohwnd commented Jul 14, 2026

Copy link
Copy Markdown
Member

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:

Runner Target Runs on
VSTest current .NET all platforms
VSTest .NET Framework (net48) Windows only
Microsoft.Testing.Platform current .NET all platforms
Microsoft.Testing.Platform .NET Framework (net48) Windows only

Projects are generated with dotnet new mstest and its switches (--test-runner, --coverage-tool, --framework), so there is no csproj editing. 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.

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 TreatWarningsAsErrors on.

nohwnd and others added 2 commits July 14, 2026 13:46
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]>
@akoeplinger
akoeplinger merged commit db14da3 into dotnet:main Jul 14, 2026
8 checks passed
@ViktorHofer

ViktorHofer commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

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.

@ViktorHofer

Copy link
Copy Markdown
Member

Filed dotnet/dotnet#7757 to track the issue

@akoeplinger

Copy link
Copy Markdown
Member

Ah thanks, I also retried a timed out test step recently but didn't correlate it back to this change.
If we can't fix it today we should disable the test so we don't have unreliable preview7 builds

@nohwnd

nohwnd commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

Do you know which build it was? I could only find 1 that had the problem.

@nohwnd

nohwnd commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

Problem is that I cannot reproduce the hang locally.

@nohwnd

nohwnd commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

Reverting, please let me know if you see timeouts after the revert is propagated to dotnet/dotnet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants