Skip to content

fix: Nested class test filtering in VS and Test Explorer#4696

Merged
thomhurst merged 1 commit intomainfrom
fix/nested-class-test-filtering
Feb 7, 2026
Merged

fix: Nested class test filtering in VS and Test Explorer#4696
thomhurst merged 1 commit intomainfrom
fix/nested-class-test-filtering

Conversation

@thomhurst
Copy link
Owner

Summary

  • Fixes nested class tests being invisible to VS Test Explorer's "Run Tests" command and appearing as flat siblings without outer class context
  • Tree node filter paths now use full OuterClass+InnerClass hierarchy instead of just InnerClass
  • ClassMetadata.Parent is now recursively populated in both source-gen and reflection modes
  • Filter matching (CouldDescriptorMatch, CouldTypeMatch) handles both full nested paths and partial names

Closes #4144

Test plan

  • New NestedClassFilteringTests engine tests verify:
    • /*/*/NestedTestClassTests+NestedClass/* finds 1 nested test
    • /*/*/NestedTestClassTests+NestedClass/Inner finds specific nested test
    • /*/*/NestedTestClassTests/Outer still finds outer class test
  • All 448 source generator snapshot tests pass
  • ExpectedStateTests pass (comprehensive pass/fail validation across all modes)
  • UidFilterMatchingTests pass (28 tests, updated to use new nested format)
  • OverlappingClassNameFilterTests pass (no regression in substring matching fix)
  • Both source-gen and reflection modes verified

🤖 Generated with Claude Code

…tors

Nested class tests were invisible to VS Test Explorer "Run Tests" and appeared
as flat siblings because tree node paths used only the innermost class name.
Now paths use the full Outer+Inner hierarchy (e.g., OuterClass+InnerClass),
ClassMetadata.Parent is recursively populated, and filter matching handles
both full and partial nested name patterns.

Closes #4144

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Contributor

claude bot commented Feb 7, 2026

Code Review

I found one issue that needs to be addressed:

Missing Snapshot Test for Nested Class Test

File: TUnit.TestProject/NestedTestClassTests.cs (new file)

According to CLAUDE.md Rule #2, changes to source generator output require running snapshot tests and committing .verified.txt files.

Since this PR adds a new test file with nested classes AND modifies the source generator to handle nested classes differently (recursive parent generation, + separator naming), a snapshot test is required following the established pattern.

Required files missing:

  • TUnit.Core.SourceGenerator.Tests/NestedTestClassTests.cs - snapshot test
  • TUnit.Core.SourceGenerator.Tests/NestedTestClassTests.Test.verified.txt - verified output

Why this matters:
The source generator now produces different output for nested classes:

  1. Recursive ClassMetadata.Parent chain
  2. Test descriptors using OuterClass+InnerClass format instead of just InnerClass

These changes should be captured in a snapshot test to prevent regressions.

Reference pattern:
See existing snapshot tests like TUnit.Core.SourceGenerator.Tests/StaticClassTests.cs for how to structure the snapshot test for this new test class.


Otherwise: The implementation looks solid. The dual-mode support (source-gen + reflection) is properly maintained, the recursive parent chain logic is correct, and the nested class naming convention using + follows .NET's standard Type.FullName format. The filter matching handles all the relevant cases (exact match, partial inner name, outer class prefix, generics). No bugs detected.

@thomhurst thomhurst merged commit ca9b265 into main Feb 7, 2026
12 of 13 checks passed
@thomhurst thomhurst deleted the fix/nested-class-test-filtering branch February 7, 2026 00:32
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.

[Bug]: Run Test (by name) in VS fails when test is in a nested class

1 participant