Skip to content

Add --test-runner option to nunit templates - #54638

Merged
Evangelink merged 4 commits into
dotnet:mainfrom
Evangelink:dev/amauryleve/nunit-template-mtp-option
Jun 8, 2026
Merged

Evangelink merged 4 commits into
dotnet:mainfrom
Evangelink:dev/amauryleve/nunit-template-mtp-option

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Partial fix for #54499 — companion to #54636 (which added the same option to the xunit templates).

This PR adds a TestRunner choice parameter to the nunit project templates (C#, F#, VB), mirroring the option already exposed by the mstest and xunit templates:

  • --test-runner VSTest (default) — preserves existing behavior, no changes to existing users.
  • --test-runner Microsoft.Testing.Platform — opts in to the MTP runner.

MTP path details

When Microsoft.Testing.Platform is selected the generated project:

  • sets EnableNUnitRunner=true, IsTestingPlatformApplication=true, OutputType=Exe;
  • bumps NUnit3TestAdapter from 5.0.0 to 6.2.0 — required because 5.0.0 transitively pins Microsoft.Testing.Platform 1.5.3, which uses an older handshake protocol incompatible with the .NET 10+ SDK dotnet test orchestrator. 6.2.0 pulls in MTP 2.1.0. The bump is conditional, so the VSTest path keeps the existing 5.0.0 pin and is not affected;
  • drops coverlet.collector (incompatible with the NUnit MTP runner per Microsoft docs);
  • for F#: excludes Program.fs (MTP auto-generates the entry point) and renames the test module to Company.TestProject1.Tests to avoid a namespace/module collision with the generated entry point;
  • creates/updates global.json with "runner": "Microsoft.Testing.Platform" via an addJsonProperty post-action.

Tests

Added NUnitProjectTemplate_WithTestRunner_CanBeInstalledAndTestsArePassing to DotnetNewTestTemplatesTests, covering 3 languages × 2 runners = 6 cases. All 6 pass locally.

Localization

Only templatestrings.en.json is updated. The .xlf files will need a follow-up /t:UpdateXlf pass.

Copilot AI review requested due to automatic review settings June 8, 2026 13:34
@Evangelink
Evangelink requested a review from a team as a code owner June 8, 2026 13:34
Adds a TestRunner choice parameter (VSTest default, Microsoft.Testing.Platform opt-in) to the C#, F#, and VB nunit templates, mirroring the naming used by the mstest and xunit templates.

For the MTP path:

- sets EnableNUnitRunner=true, IsTestingPlatformApplication=true, OutputType=Exe

- bumps NUnit3TestAdapter to 6.2.0 (which transitively brings Microsoft.Testing.Platform 2.1.0, the protocol version required by the .NET 10+ SDK dotnet test orchestrator)

- drops coverlet.collector (incompatible with the NUnit MTP runner)

- for F#: excludes Program.fs (MTP auto-generates the entry point) and uses a nested module name (Company.TestProject1.Tests) to avoid a namespace/module collision with the generated entry point

- creates/updates global.json with the test runner property

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a --test-runner choice parameter to the built-in nunit project templates (C#/F#/VB) so newly created NUnit projects can opt into Microsoft.Testing.Platform (while keeping VSTest as the default), and adds integration-test coverage for the new combinations.

Changes:

  • Introduces a TestRunner choice symbol (VSTest default, Microsoft.Testing.Platform opt-in) across NUnit templates, including CLI/IDE host wiring and English localization.
  • Updates generated project files to switch to the MTP runner shape (properties, conditional package references, global.json post-action).
  • Adds an integration test covering 3 languages × 2 runners to validate template install + dotnet test success.
Show a summary per file
File Description
test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs Adds NUnit template integration coverage for both VSTest and MTP runners.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-CSharp/Company.TestProject1.csproj Adds MTP runner properties and conditional package refs for the C# NUnit template.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-CSharp/.template.config/template.json Adds TestRunner symbol and MTP global.json post-action for the C# NUnit template.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-CSharp/.template.config/localize/templatestrings.en.json Adds English localization for TestRunner and the global.json post-action (C#).
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-CSharp/.template.config/ide.host.json Enables IDE persistence/visibility for TestRunner (C#).
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-CSharp/.template.config/dotnetcli.host.json Wires --test-runner CLI alias (C#).
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-FSharp/UnitTest1.fs Adjusts module name under MTP to avoid entrypoint/module collisions.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-FSharp/Company.TestProject1.fsproj Adds MTP runner properties, excludes Program.fs for MTP, and updates conditional package refs.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-FSharp/.template.config/template.json Adds TestRunner symbol, excludes Program.fs under MTP, and adds MTP global.json post-action.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-FSharp/.template.config/localize/templatestrings.en.json Adds English localization for TestRunner and the global.json post-action (F#).
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-FSharp/.template.config/ide.host.json Enables IDE persistence/visibility for TestRunner (F#).
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-FSharp/.template.config/dotnetcli.host.json Wires --test-runner CLI alias (F#).
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-VisualBasic/Company.TestProject1.vbproj Adds MTP runner properties and conditional package refs for the VB NUnit template.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-VisualBasic/.template.config/template.json Adds TestRunner symbol and MTP global.json post-action for the VB NUnit template.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-VisualBasic/.template.config/localize/templatestrings.en.json Adds English localization for TestRunner and the global.json post-action (VB).
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-VisualBasic/.template.config/ide.host.json Enables IDE persistence/visibility for TestRunner (VB).
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/NUnit-VisualBasic/.template.config/dotnetcli.host.json Wires --test-runner CLI alias (VB).

Copilot's findings

  • Files reviewed: 17/17 changed files
  • Comments generated: 3

@Evangelink
Evangelink force-pushed the dev/amauryleve/nunit-template-mtp-option branch from 33b8d92 to 31ec589 Compare June 8, 2026 13:41
Move Microsoft.NET.Test.Sdk and NUnit3TestAdapter into the TestRunner != "Microsoft.Testing.Platform" conditional block in the NUnit C#, F#, and VB templates. Both packages are VSTest-specific and pull in unnecessary/possibly conflicting test platform assets when the MTP runner is selected, mirroring how the MSTest template handles its MTP path.

Co-authored-by: Copilot <[email protected]>
@Evangelink
Evangelink enabled auto-merge June 8, 2026 14:15
@Evangelink
Evangelink merged commit 37b9f2e into dotnet:main Jun 8, 2026
25 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 10, 2026
@Evangelink
Evangelink deleted the dev/amauryleve/nunit-template-mtp-option branch June 11, 2026 08:01
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