Skip to content

Support F# modules as MSTest test containers - #11830

Merged
Amaury Levé (Evangelink) merged 3 commits into
mainfrom
dev/amauryleve/fsharp-module-discovery
Oct 8, 2026
Merged

Amaury Levé (Evangelink) merged 3 commits into
mainfrom
dev/amauryleve/fsharp-module-discovery

Conversation

@Evangelink

Copy link
Copy Markdown
Member

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:

& .\eng\build.ps1 -build -projects test\IntegrationTests\MSTest.Acceptance.IntegrationTests\MSTest.Acceptance.IntegrationTests.csproj -c Release -bl

Passed, zero warnings/errors. The exact acceptance invocation was:

$env:DOTNET_ROOT="$(Get-Location)\.dotnet"
$env:PATH="$env:DOTNET_ROOT;$env:PATH"
$env:DOTNET_ROLL_FORWARD='Major'
.\.dotnet\dotnet.exe artifacts\bin\MSTest.Acceptance.IntegrationTests\Release\net11.0\MSTest.Acceptance.IntegrationTests.dll --filter 'FullyQualifiedName~FSharpModuleTests|FullyQualifiedName~FSharpTests' --no-ansi --progress off --report-trx --report-trx-filename fsharp-acceptance.trx --results-directory "$(Get-Location)\artifacts\TestResults\fsharp-modules"

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.

The three unit-test loops were:

foreach ($area in 'Discovery','Execution','Extensions') {
    .\.dotnet\dotnet.exe artifacts\bin\MSTestAdapter.PlatformServices.UnitTests\Release\net8.0\MSTestAdapter.PlatformServices.UnitTests.dll --treenode-filter "/*/*$area/*/*" --no-ansi --progress off --report-trx --report-trx-filename "fsharp-$area-net8.trx" --results-directory "$(Get-Location)\artifacts\TestResults\fsharp-modules"
}
foreach ($area in 'Discovery','Execution','Extensions') {
    .\.dotnet\dotnet.exe artifacts\bin\MSTestAdapter.PlatformServices.UnitTests\Release\net9.0\MSTestAdapter.PlatformServices.UnitTests.dll --treenode-filter "/*/*$area/*/*" --no-ansi --progress off --report-trx --report-trx-filename "fsharp-$area-net9.trx" --results-directory "$(Get-Location)\artifacts\TestResults\fsharp-modules"
}
foreach ($area in 'Discovery','Execution','Extensions') {
    & .\artifacts\bin\MSTestAdapter.PlatformServices.UnitTests\Release\net462\MSTestAdapter.PlatformServices.UnitTests.exe --treenode-filter "/*/*$area/*/*" --no-ansi --progress off --report-trx --report-trx-filename "fsharp-$area-net462.trx" --results-directory "$(Get-Location)\artifacts\TestResults\fsharp-modules"
}

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
Copilot AI balanced review requested due to automatic review settings October 8, 2026 12:30
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Oct 8, 2026

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.

🔵 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.
File Description
test/​UnitTests/​MSTestAdapter.PlatformServices.UnitTests/​Execution/​TypeCacheTests.cs Updates lifecycle diagnostic expectation.
test/​UnitTests/​MSTestAdapter.PlatformServices.UnitTests/​Discovery/​TypeValidatorTests.cs Verifies C# behavior remains unchanged.
test/​IntegrationTests/​MSTest.Acceptance.IntegrationTests/​FSharpTests.cs Adds basic F# module coverage.
test/​IntegrationTests/​MSTest.Acceptance.IntegrationTests/​FSharpModuleTests.cs Adds comprehensive module acceptance coverage.
src/​TestFramework/​TestFramework/​Attributes/​TestMethod/​TestMethodAttribute.cs Documents module test functions.
src/​TestFramework/​TestFramework/​Attributes/​TestMethod/​TestClassAttribute.cs Documents optional module annotation.
src/​TestFramework/​TestFramework/​Attributes/​Lifecycle/​Initialization/​TestInitializeAttribute.cs Documents static module initialization.
src/​TestFramework/​TestFramework/​Attributes/​Lifecycle/​Cleanup/​TestCleanupAttribute.cs Documents static module cleanup.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.zh-Hant.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.zh-Hans.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.tr.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.ru.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.pt-BR.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.pl.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.ko.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.ja.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.it.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.fr.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.es.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.de.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​xlf/​Resource.cs.xlf Regenerates localized diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​Resources/​Resource.resx Updates signature diagnostics.
src/​Adapter/​MSTestAdapter.PlatformServices/​InternalAPI/​InternalAPI.Unshipped.txt Tracks internal API changes.
src/​Adapter/​MSTestAdapter.PlatformServices/​Extensions/​TypeExtensions.cs Detects F# module metadata.
src/​Adapter/​MSTestAdapter.PlatformServices/​Extensions/​MethodInfoExtensions.cs Validates static module methods.
src/​Adapter/​MSTestAdapter.PlatformServices/​Execution/​TypeCache.ClassInfo.cs Creates constructor-free module metadata.
src/​Adapter/​MSTestAdapter.PlatformServices/​Execution/​TypeCache.AssemblyInfo.cs Discovers module fixtures.
src/​Adapter/​MSTestAdapter.PlatformServices/​Execution/​TestMethodInfo.Lifecycle.cs Supports null module instances in fixtures.
src/​Adapter/​MSTestAdapter.PlatformServices/​Execution/​TestMethodInfo.Execution.cs Executes and cleans up static tests.
src/​Adapter/​MSTestAdapter.PlatformServices/​Execution/​TestClassInfo.cs Represents module activation explicitly.
src/​Adapter/​MSTestAdapter.PlatformServices/​Discovery/​TypeValidator.cs Infers valid F# module containers.
src/​Adapter/​MSTestAdapter.PlatformServices/​Discovery/​TestMethodValidator.cs Accepts static module test functions.
src/​Adapter/​MSTest.TestAdapter/​PACKAGE.md Documents F# module usage and constraints.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 8, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. labels Oct 8, 2026
@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) October 8, 2026 13:22
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
Copilot AI balanced review requested due to automatic review settings October 8, 2026 14:08
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/approved Proposal approved; ready for implementation. labels Oct 8, 2026

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.

🟡 Changes recommended

Module validation accepts instance members that execution invokes without an instance, and one F# diagnostic remains class-oriented.

2 open findings

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Oct 8, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Oct 8, 2026

@github-actions github-actions Bot 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.

🧪 Test quality review — PR #11830

🧵 Parallel safety

STATUS: CLEAN

Test assembly Scope Workers Notes
MSTest.Acceptance.IntegrationTests MethodLevel CPU count No hazards found
MSTestAdapter.PlatformServices.UnitTests off (TestContainer engine) n/a Readiness-only, not a live issue

Key checks performed by the specialist:

  • 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

GradeTestMutationNotesHow 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.

🤖 Automated content by GitHub Copilot. Generated by the Test Quality Review on PR (on open / sync) workflow. · copilot · auto · 368.6 AIC · ⌖ 18.1 AIC · ⊞ 19.6K · ◷

@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Oct 8, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Oct 8, 2026
Reject instance members on constructor-free module containers during discovery and signature validation. Add module metadata regression coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 065f8eb0-d073-439e-82c4-04af07cded06
Copilot AI balanced review requested due to automatic review settings October 8, 2026 14:45
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 8, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Oct 8, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Oct 8, 2026

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.

🔵 Needs a closer look

Class-specific TestContext validation can still reject valid F# modules, and one return-type path emits the wrong diagnostic.

0 open findings

2 resolved since last review
Previously missed (2)

In code that hasn't changed since last review

Medium severity Skip instance TestContext validation for F# modules

src/​Adapter/​MSTestAdapter.PlatformServices/​Discovery/​TypeValidator.cs:60

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.

Low severity Route F# generic ValueTask returns to the correct diagnostic

src/​Adapter/​MSTestAdapter.PlatformServices/​Discovery/​TestMethodValidator.cs:75

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.

@Evangelink
Amaury Levé (Evangelink) merged commit 1e67007 into main Oct 8, 2026
36 of 42 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/fsharp-module-discovery branch October 8, 2026 15:44
@github-actions github-actions Bot removed the state/approved Proposal approved; ready for implementation. label Oct 8, 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.

3 participants