Add MSTest.AotReflection.SourceGeneration.UnitTests#9004
Open
Evangelink wants to merge 2 commits into
Open
Conversation
Adds a focused unit-test project for the AotReflection source generator PoC introduced in microsoft#8574. The PoC had no test coverage until now. Coverage highlights (13 tests): - Support types emission (TestClassReflectionInfo, TestMethodReflectionInfo, TestPropertyReflectionInfo, TestConstructorReflectionInfo). - Registry emission shape and namespace (MSTest.SourceGenerated). - Empty registry when no [TestClass] is present. - Skipping of static / abstract / open-generic test classes. - Constructor invoker, parameter types / names, async return shape. - Class-level attribute capture; property getter & setter delegate text. - Compile-clean snapshot (catches CS errors the generator may introduce). - Incrementality: support-types step is cached when input is unchanged. Also: - Adds MSTest.AotReflection.SourceGeneration to TestFx.slnx and MSTest.slnf (missing since microsoft#8574). - Adds [InternalsVisibleTo] for the new test project (generator class is internal sealed). Part of microsoft#1837. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new unit test project for the MSTest.AotReflection.SourceGeneration proof-of-concept generator, and wires the generator + tests into the repo’s main solution and MSTest solution filter. This provides regression protection for upcoming NativeAOT-related work tracked under #1837.
Changes:
- Added new test project
test/UnitTests/MSTest.AotReflection.SourceGeneration.UnitTests(MTP host) with focused Roslyn-driven generator behavior tests. - Included
MSTest.AotReflection.SourceGenerationinTestFx.slnxandMSTest.slnf. - Granted the new test assembly internal access to the generator via
InternalsVisibleTo.
Show a summary per file
| File | Description |
|---|---|
| TestFx.slnx | Adds the generator project and the new unit test project to the full solution. |
| MSTest.slnf | Ensures the generator project is included in the MSTest solution filter. |
| src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj | Adds InternalsVisibleTo so unit tests can instantiate internal generator types. |
| test/UnitTests/MSTest.AotReflection.SourceGeneration.UnitTests/MSTest.AotReflection.SourceGeneration.UnitTests.csproj | New unit test project referencing Roslyn + the generator project. |
| test/UnitTests/MSTest.AotReflection.SourceGeneration.UnitTests/Program.cs | MTP/MSTest runner entry point consistent with other unit test apps in the repo. |
| test/UnitTests/MSTest.AotReflection.SourceGeneration.UnitTests/MSTestReflectionMetadataGeneratorTests.cs | Adds 13 generator behavior tests covering registry/support-type emission, filtering, invokers, and compile-clean output. |
Copilot's findings
- Files reviewed: 6/6 changed files
- Comments generated: 2
This was referenced Jun 10, 2026
Two RunGenerators calls were performed but only the final result was inspected, so the test never validated that the second run reused cached output. Capture both run results, assert the generated sources match between runs (deterministic output), and assert TrackedOutputSteps for the second run all report Cached or Unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of #1837.
Why
MSTest.AotReflection.SourceGenerationwas added in #8574 as a proof of concept and has been sitting insrc/Analyzers/with no unit tests. This PR adds a focused unit-test project so that the upcoming follow-up PRs (inheritance walking, assembly-level attributes,[DataRow]/[DynamicData]materialization, async invoker shape, analyzer diagnostics, bridging into the shippingSourceGeneratedReflectionDataProvider) can land with regression safety.What
New project:
test/UnitTests/MSTest.AotReflection.SourceGeneration.UnitTestsMirrors the layout of the sibling
MSTest.SourceGeneration.UnitTests(MTP host, AwesomeAssertions,Microsoft.CodeAnalysis.CSharp-driven generator runs).13 tests covering the current PoC behaviour:
TestClassReflectionInfo,TestMethodReflectionInfo,TestPropertyReflectionInfo,TestConstructorReflectionInfo).MSTest.SourceGeneratednamespace.[TestClass]is present.static/abstract/ open-generic test classes.Reason == Cachedwhen input is unchanged.Plus housekeeping that should have been part of #8574:
MSTest.AotReflection.SourceGenerationtoTestFx.slnx(was missing from the full solution).MSTest.slnf(was missing from the build filter).[InternalsVisibleTo]for the new test project (the generator class isinternal sealed).Out of scope (will be follow-ups)
typeof(T?)verbatim, which is invalid C#. A separate small bug-fix PR will strip nullable annotations fromtypeof(...)emission sites and add a regression test that uses nullable shapes.[DataRow], async invoker, analyzer diagnostics, bridge intoSourceGeneratedReflectionDataProvider) is being prepared.Validation
dotnet build+dotnet runfrom the new test project:13/13passing,0warnings.