You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support F# modules as MSTest test containers - #11830
F# tests naturally use module functions rather than instance-based test classes. MSTest currently requires [TestClass] and rejects static test methods, preventing that idiomatic style. This change discovers [<TestMethod>] functions in F# modules without requiring [<TestClass>].
The shared adapter recognizes F# compiler metadata without an FSharp.Core dependency and runs static test and lifecycle functions through the existing execution pipeline. Module declarations honor existing class-level attributes, including categories, properties, ignore, retry, and parallelization controls. Explicit/custom TestClass attributes remain supported. Constructor-free activation is represented explicitly so cleanup and global fixtures still run after failures and timeouts.
Compatibility and scope
C#, VB, and ordinary F# classes retain their existing attribute and instance-method requirements.
Nested modules are independent containers; outer-module metadata and fixtures do not propagate.
Mutable module state is shared across tests and retries. An adapter upgrade can now discover previously ignored annotated module functions.
Supported return types remain void, Task, and non-generic ValueTask. This does not add F# Async<unit> or F# source-generator/AOT support.
No new public API. Updated documentation, internal API tracking, signature diagnostics, and generated localization catalogs.
Related issue: N/A.
Validation
.\build.cmd -c Release -pack -bl: passed, zero warnings/errors; produced the actual Windows shipping layout for MSTest 4.6.0-dev and MTP 2.6.0-dev.
Packed-package F# acceptance coverage: 66 passed. Exercises MTP and VSTest on .NET 8/10, plus strict-discovery class/module coverage on .NET Framework 4.6.2. Covers file-level/nested modules, custom attributes, data, async functions, fixtures, context, attachments, parallel scheduling, failures, and cooperative/noncooperative timeout cleanup.
Affected adapter discovery/execution/extension unit tests: 2,004 passed across net8.0 (670), net9.0 (670), and net462 (664).
git diff --check and UTF-8 BOM checks: passed.
Test commands and result artifacts
After packing, the acceptance host was rebuilt with:
Passed, exit code 0, 66/66. Major roll-forward launches the net11 acceptance harness with the repository's pinned .NET 12 SDK runtime; generated test assets use the repository's installed target runtimes.
Passed, exit code 0 for all nine runs. The ten final TRX reports are retained locally under artifacts\TestResults\fsharp-modules; build binary logs are retained under artifacts\log\Release.
Discover module test functions without TestClass, preserve existing class requirements, and reuse the adapter execution pipeline for static tests, lifecycle functions, and class-level attributes.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 494c2322-e61f-487d-aa5c-726433d7fe94
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Core discovery, reflection, timeout cleanup, and cross-host execution semantics require final human validation despite comprehensive coverage.
0 open findings
What changed in this PR
Adds idiomatic F# module discovery and execution to MSTest while preserving existing class behavior.
Changes:
Recognizes F# compiler module metadata and permits static test/lifecycle functions.
Supports constructor-free execution, cleanup, metadata, retries, and parallelization.
Adds cross-host acceptance coverage, documentation, diagnostics, localization, and API tracking.
🟡 Confidence at a glance: adapter discovery and execution
No actionable defect found, but reflection, timeout cleanup, and cross-host lifecycle changes warrant human sign-off.
Keep existing class signature resources unchanged and generate new F# module diagnostics, so newly locked tokens do not invalidate existing translation targets. Cover module-specific discovery warnings and preserve legacy class diagnostics.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 494c2322-e61f-487d-aa5c-726433d7fe94
FSharpModuleTests.cs's 16 new method-level-parallel acceptance tests each use a fresh TempDirectory and pass marker paths only to a child process (never mutate the parent process environment), so no class-level [DoNotParallelize] is needed — matches the established sibling convention.
The embedded F# asset's own [<assembly: Parallelize>]/[<DoNotParallelize>] govern a separate, isolated child-process binary and don't affect the parent acceptance-test process.
TypeValidatorTests' two new tests reuse the shared _warnings field, but TestContainer creates a fresh class instance (and thus a fresh, empty _warnings) per test method — no cross-test leak.
TypeExtensions.cs's new ConcurrentDictionary<Type,bool> cache is a race-free, idempotent memoization; TestClassInfo.Constructor is set once at construction and never mutated, so the nullable-Constructor change doesn't alter its existing concurrency contract.
No findings to report.
Per-test grades
Grade
Test
Mutation
Notes
How to improve
A (90–100)
new FSharpModuleTests. DiscoversModulesWithoutTestClassAndPreservesFSharpClassValidation
6/6 killed
Exact discovered-name set assertion plus a negative control for non-public synthesized types.
—
A (90–100)
new FSharpModuleTests. RunsNamedNestedExplicitAndCustomModulesAlongsideExistingClass
8/8 killed
Exact marker-sequence assertions distinguish named/nested/explicit/custom modules and an existing class.
—
A (90–100)
new FSharpModuleTests. RunsDataRowsDynamicDataTaskAndValueTaskModuleFunctions
6/6 killed
Exact ordered marker set verifies DataRow, DynamicData, Task, and ValueTask module functions.
—
A (90–100)
new FSharpModuleTests. HonorsModuleCategoriesAndPropertiesWithMethodMetadata
6/6 killed
Three independent filter runs isolate module-level vs. method-level category/property inheritance.
—
A (90–100)
new FSharpModuleTests. DoesNotInheritContainingModuleMetadataOrLocalFixtures
4/4 killed
Negative assertions prove nested-module isolation from containing module metadata/fixtures.
—
A (90–100)
new FSharpModuleTests. HonorsModuleAndMethodIgnoreButDoesNotIgnoreNestedModule
5/5 killed
Checks skip count, absence of marker files for ignored tests, and that nested siblings still run.
—
A (90–100)
new FSharpModuleTests. HonorsModuleRetryAndMethodOverride
4/4 killed
Exact attempt-count marker sequences verify module-level retry and a method-level override.
—
A (90–100)
new FSharpModuleTests. DoesNotInheritRetryIntoNestedModule
3/3 killed
Single-attempt marker sequence proves the nested module did not inherit the outer retry count.
—
A (90–100)
new FSharpModuleTests. RunsStaticLifecycleAndGlobalFixturesWithCurrentContextAndResultFile
7/7 killed
Exact 7-step lifecycle order plus TRX attachment path/content assertions.
—
A (90–100)
new FSharpModuleTests. HonorsModuleDoNotParallelizeAndKeepsNestedModuleParallelizable
4/4 killed
Deterministic TaskCompletionSource handshake (no sleeps) catches accidental serialization of the nested module.
—
A (90–100)
new FSharpModuleTests. BodyFailureStillRunsStaticAndGlobalCleanup
4/4 killed
Exact marker sequence plus failure-message assertion isolate body-failure cleanup behavior.
—
A (90–100)
new FSharpModuleTests. InitializeFailureSkipsBodyButStillRunsStaticAndGlobalCleanup
4/4 killed
Marker sequence proves body was skipped while cleanup/global fixtures still ran.
—
A (90–100)
new FSharpModuleTests. CleanupFailureIsReportedAndGlobalCleanupStillRuns
4/4 killed
Checks failure is reported and global cleanup still executes after a cleanup-phase failure.
—
A (90–100)
new FSharpModuleTests. CooperativeTimeoutRunsCleanupOnceWithFreshCancellationToken
4/4 killed
Marker sequence verifies cooperative cancellation and a single cleanup run.
—
A (90–100)
new FSharpModuleTests. NonCooperativeTimeoutRunsCleanupOnceWithoutConstructingModule
3/3 killed
Proves non-cooperative timeout still runs cleanup exactly once without instance construction.
—
A (90–100)
mod FSharpTests. DiscoversFSharpTestWithSpaceAndDotInName
2/2 killed
Adds a containment assertion for the new module test alongside the existing class test.
—
A (90–100)
mod FSharpTests. RunsFSharpTestWithSpaceAndDotInName
2/2 killed
Tightened succeeded-count assertion (1→2) exactly matches the two test functions in the asset.
—
A (90–100)
new TypeValidatorTests. IsValidTestClassShouldNotInferCSharpContainersFromTestMethods
2/2 killed
Proves an ordinary static C# class with [TestMethod] is still rejected, unlike an F# module.
—
A (90–100)
new TypeValidatorTests. IsValidTestClassShouldRejectAnnotatedCSharpStaticContainers
1/1 killed
Proves [TestClass] alone cannot make a static C# class valid (non-F#-module path still rejected).
—
This advisory review is heuristic and non-blocking.
Re-run the combined review with /review-tests, or only the parallel-safety specialist with /parallel-audit.
F# module values are emitted as static properties, but after this branch accepts the module, HasCorrectTestContextSignature still applies the instance-class rule and rejects any module-level value whose type is TestContext. TestClassInfo also still calls ResolveTestContext, so a module value named TestContext can trigger class-injection validation even though modules intentionally have no instance. Such modules are therefore skipped or fail inspection despite otherwise valid test functions. Bypass TestContext-property validation and resolution for F# modules.
Route F# generic ValueTask returns to the correct diagnostic
A static F# module function returning ValueTask<T> satisfies every condition except its return type, so this branch selects UTA_ErrorGenericValueTaskReturnType. That resource describes a “Method ... in class” and gives a C# example, bypassing the new F#-specific diagnostic. Route this case to the module signature message (which already says non-generic ValueTask) or add an F#-specific generic-ValueTask resource.
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
F# tests naturally use module functions rather than instance-based test classes. MSTest currently requires
[TestClass]and rejects static test methods, preventing that idiomatic style. This change discovers[<TestMethod>]functions in F# modules without requiring[<TestClass>].The shared adapter recognizes F# compiler metadata without an
FSharp.Coredependency and runs static test and lifecycle functions through the existing execution pipeline. Module declarations honor existing class-level attributes, including categories, properties, ignore, retry, and parallelization controls. Explicit/customTestClassattributes remain supported. Constructor-free activation is represented explicitly so cleanup and global fixtures still run after failures and timeouts.Compatibility and scope
void,Task, and non-genericValueTask. This does not add F#Async<unit>or F# source-generator/AOT support.Related issue: N/A.
Validation
.\build.cmd -c Release -pack -bl: passed, zero warnings/errors; produced the actual Windows shipping layout for MSTest4.6.0-devand MTP2.6.0-dev.net8.0(670),net9.0(670), andnet462(664).git diff --checkand UTF-8 BOM checks: passed.Test commands and result artifacts
After packing, the acceptance host was rebuilt with:
Passed, zero warnings/errors. The exact acceptance invocation was:
Passed, exit code 0, 66/66.
Majorroll-forward launches the net11 acceptance harness with the repository's pinned .NET 12 SDK runtime; generated test assets use the repository's installed target runtimes.The three unit-test loops were:
Passed, exit code 0 for all nine runs. The ten final TRX reports are retained locally under
artifacts\TestResults\fsharp-modules; build binary logs are retained underartifacts\log\Release.