Fix dotnet test --filter for FullyQualifiedName and DisplayName#548
Closed
niclasahlqvist wants to merge 1 commit into
Closed
Fix dotnet test --filter for FullyQualifiedName and DisplayName#548niclasahlqvist wants to merge 1 commit into
niclasahlqvist wants to merge 1 commit into
Conversation
Two issues prevented test filtering from working: 1. The supportedProperties array and property lookup dictionary were keyed by TestProperty.Id (e.g. "TestCase.FullyQualifiedName") but the vstest filter framework passes the Label (e.g. "FullyQualifiedName"). Added both Id and Label as dictionary keys. 2. TestObject.GetPropertyValue() returns empty string for well-known properties like DisplayName across ObjectModel assembly versions. Replaced the property bag lookup with direct TestCase property access for FullyQualifiedName and DisplayName. Trait-based filters (Tag, Subject, ClassName) were already working.
Contributor
Author
|
CI note: The build step succeeds, all net8.0 tests pass (423 specs, 0 failures). The |
Contributor
Author
|
Not sure how active this repo is anymore so I'll throw in a ping @robertcoltheart |
Member
|
Closing in favor of machine/machine.specifications.runner.visualstudio#175 |
Contributor
Author
|
@robertcoltheart Alright - will there be a nuget release aswell? |
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.
Summary
dotnet test --filterhas been broken forFullyQualifiedNameandDisplayNameproperties. Tests show up in--list-testsbut--filter "FullyQualifiedName~MySpec"returns "No test matches". This fixes both.Relates to #349, #327
Root Cause
Two bugs in
SpecificationFilterProvider:1. Dictionary keyed by
TestProperty.Idinstead ofTestProperty.LabelThe
supportedPropertiesarray and property lookup dictionary usedTestCaseProperties.FullyQualifiedName.Id("TestCase.FullyQualifiedName") as keys, but the vstest filter framework passes the Label ("FullyQualifiedName") to the property value provider callback. The lookup silently returnednullfor every test, filtering everything out.Fix: Added both
.Idand.Labelas dictionary keys for backwards compatibility.2.
TestObject.GetPropertyValue()returns empty for well-known propertiestestCase.GetPropertyValue(TestCaseProperties.DisplayName)returns empty string even thoughtestCase.DisplayNamehas the correct value. This appears to be a vstestTestObjectproperty bag issue acrossObjectModelassembly versions — the property is set via theDisplayNamesetter but isn't reliably retrievable through the generic property bag.Fix: Replaced the
TestObjectproperty bag lookup with directTestCaseproperty access forFullyQualifiedNameandDisplayName. Trait-based properties (Tag,Subject,ClassName) continue to use the existing Traits collection lookup, which was already working.Verified Filters
All tested against a real project with 2400+ MSpec tests:
FullyQualifiedName--filter "FullyQualifiedName~MySpec"DisplayName--filter "DisplayName~my spec"ClassName--filter "ClassName~MyClass"Subject--filter "Subject~My Subject"Tag--filter "Tag~mytag"Changes
SpecificationFilterProvider.cs— rewroteGetPropertyValueto read well-known properties directly fromTestCase, added Label keys to dictionary