Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestCaseFilter with custom properties #3015

Merged
merged 9 commits into from
Jun 10, 2024
Merged

Conversation

engyebrahim
Copy link
Member

@engyebrahim engyebrahim commented May 28, 2024

fix: #731
fix: #201

@engyebrahim engyebrahim marked this pull request as draft May 28, 2024 14:14
@engyebrahim engyebrahim changed the title add traits on filter checks TestCaseFilter with custom properties May 28, 2024
@engyebrahim engyebrahim marked this pull request as ready for review June 3, 2024 08:32
Comment on lines +49 to +87
[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
public async Task UsingTestPropertyForOwnerAndPriorityAndTestCategory_TestsFailed(string currentTfm)
{
var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm);

TestHostResult testHostResult = await testHost.ExecuteAsync("--filter tree!~one");

testHostResult.AssertOutputContains("""
failed PriorityTest 0ms
UTA023: TestClass: Cannot define predefined property Priority on method PriorityTest.
failed OwnerTest 0ms
UTA023: TestClass: Cannot define predefined property Owner on method OwnerTest.
failed TestCategoryTest 0ms
UTA023: TestClass: Cannot define predefined property TestCategory on method TestCategoryTest.
""");
}

[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
public async Task RunWithFilter_UsingTestPropertyForOwner_FilteredButTestsFailed(string currentTfm)
{
var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm);

TestHostResult testHostResult = await testHost.ExecuteAsync("--filter owner=testOwner");

testHostResult.AssertOutputContains("""
failed OwnerTest 0ms
UTA023: TestClass: Cannot define predefined property Owner on method OwnerTest.
""");
}

[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
public async Task RunWithFilter_UsingTestPropertyForPriorityAndTestCategory_NotFiltered(string currentTfm)
{
var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm);

TestHostResult testHostResult = await testHost.ExecuteAsync("--filter TestCategory=category|Priority=1");

testHostResult.AssertOutputContains("Zero tests ran");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these tests proving? The errors seem unrelated to adding a new functionality that can filter on additional test categories.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup it's not related to the fix, I just want to document that behaviour as it's related to TestProperty if would change it in future

Copy link
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nohwnd I'll let you do the final approval here as you have been following more closely.

Copy link
Member

@nohwnd nohwnd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is useful functionality and it aligns well with traits on tests being used as properties of the test.

There is some slight perf impact when the property filter is enabled, but it is not the mainline scenario (discovery under VS), and we should be able to implement this in a more optimized way with ease if we drop object model from mstest.

@Evangelink
Copy link
Member

Nice work @engyebrahim :shipit:

@Evangelink Evangelink merged commit eac79e1 into main Jun 10, 2024
4 of 6 checks passed
@Evangelink Evangelink deleted the Enji/add-testproperty-filter branch June 10, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants