Skip to content

Remove redundant .NET and language version settings in tests - #1367

Merged
meziantou merged 4 commits into
mainfrom
feature/remove-redundant-dotnet-versions-832fde
Aug 31, 2026
Merged

meziantou merged 4 commits into
mainfrom
feature/remove-redundant-dotnet-versions-832fde

Conversation

@meziantou

Copy link
Copy Markdown
Owner

What

Removes the explicit target framework, ASP.NET Core and C# language version settings in the tests when the defaults of the testing harness are enough.

  • ~200 test.ReferenceAssemblies = ReferenceAssemblies.Net.NetXX; assignments removed, plus the equivalent object initializers (new CodeFixTest { ReferenceAssemblies = ... }).
  • Pinned ASP.NET Core and NuGet combinations replaced by the shared defaults: ReferenceAssemblies.Net.Net80.AddAspNetCore("8.0.0") becomes test.ReferenceAssemblies.AddAspNetCore(), and ...Net80.AddPackages([...]) becomes test.ReferenceAssemblies.AddPackages([...]).
  • 188 explicit test.LanguageVersion = ... assignments removed, plus 13 more in UseStringComparerAnalyzerTests that only existed to lift the C# 9 class default back up to C# 12.
  • UseRegexSourceGeneratorAnalyzerTests gets a CreatePartialMethodTest helper (.NET 7 + C# 11) instead of repeating the language version in 23 tests, which also lets the partial property tests drop their Net90 overrides.
  • The now unused using Microsoft.CodeAnalysis.Testing; and using Microsoft.CodeAnalysis.CSharp; directives are removed.

Why

Most tests were pinning a framework or a language version that predates the default of the harness, which hides which tests actually depend on a specific version.

What is kept

Every setting that is load bearing was verified by removing it and observing the failures:

  • Tests that assert version specific behavior (ProcessWaitForExit_NET5, Net5_NoDiagnostic, RefStruct_CSharp12, CannotBeReadOnly_CSharp7, InjectProperty_AspNetCore8_NoDiagnostic, ...).
  • LanguageVersion.Preview for union types, closed types and System.Threading.Lock: Latest is below those features on the older Roslyn versions.
  • The regex source generator tests: the .NET 11 generator emits collection expressions, which need C# 12, and the code fixer generates a partial property as soon as the language supports it.
  • The netstandard and net48 targets, and the DI based tests whose types are not in the .NET 11 ASP.NET Core reference pack.

Testing

dotnet test --max-parallel-test-modules 2: 19013 passed, 0 failed, on Roslyn 4.8, 4.14, 5.0, 5.6 and 5.9.

Note for the reviewer

Names such as Dictionary_String_CollectionExpression_DefaultOnCSharp12_ShouldNotReportDiagnostic now run with the default language version instead of exactly C# 12. The behavior is identical, but tell me if you prefer to keep the explicit pin so the names keep matching.

The tests that expect the code fixer to generate a partial method now use
a CreatePartialMethodTest helper that pins .NET 7 and C# 11, instead of
repeating the language version in every test. CreateTest uses the default
target framework, so the partial property tests no longer need to override
the reference assemblies.
@meziantou
meziantou merged commit 087a754 into main Aug 31, 2026
13 checks passed
@meziantou
meziantou deleted the feature/remove-redundant-dotnet-versions-832fde branch August 31, 2026 18:08
This was referenced Aug 31, 2026
This was referenced Sep 25, 2026
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.

1 participant