-
Notifications
You must be signed in to change notification settings - Fork 163
Support when clause for test launch configurations #1638
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
Conversation
|
@microsoft-github-policy-service agree |
|
Hi @ReubenFrankel, Thank you for your contribution! I have one concern about comparing with ID. Since that a kind of internal property and might be changed in the future. It would be better to compare with something that users are aware of and cleared defined in some specs. Maybe like, a fully qualified name? |
As far as I can see |
|
Thank you @ReubenFrankel for quick response! I will take a look soon. |
409f6d4 to
ac7888a
Compare
|
Some questions:
It will become complex for methods because JUnit 5 and TestNG allows methods to override. Below is how the extension constructs the Line 43 in 22a11be
For JUnit5 and TestNG, the name of the test method contains the parameter list, while for JUnit 4, it's only the name of the method. I checked the document of Surefire Plugin, looks like it does not support methods filtering? |
My personal use-case for this feature only really requires inclusion (i.e. I only want a specific configuration to be available when I'm running tests from a specific class). I'm sure there is a case for exclusion, in which case it might make more sense to implement something like: {
"filters": {
"pattern": {
"include": ...
"exclude": ...
}
}
}The reason I chose regex in the end here is:
{
"filters": {
"pattern": "TestClass"
}
}{
"filters": {
"pattern": "testMethod"
}
}{
"filters": {
"pattern": "TestClass#testMethod"
}
}
A fully-qualified method name takes the pattern
I don't think this changes anything? Overridden methods will have the same name and signature, so just the class name changes, which is easy enough to match: {
"filters": {
"pattern": "(TestClass|AnotherTestClass)#testMethod"
}
}
JUnit4 {
"filters": {
"pattern": "TestClass#testMethod"
}
}JUnit5/TestNG {
"filters": {
"pattern": "TestClass#testMethod\(String testArgument\)"
}
} |
|
Thank you @ReubenFrankel. All of your comments make sense to me. Then let's discuss some details about the implementation.
or Considering the tag filtering already adopts the second style, we can adopt it for the pattern filter to make all filter settings align. WDYT?
|
I'm not sure this can work with regex, since it will just treat the I take it this means you want to support multiple patterns for a single configuration, which I hadn't considered but also makes sense.
How do you imagine a glob pattern working for a fully-qualified name? I'm not sure that makes sense since its not a filename or path. If you mean like a wildcard character, then it's sort of heading towards the Surefire plugin or custom implementation. |
So, if the first character of the pattern is
Personally, I think using regular expression is a good idea. Because IDEA also support that, and the name of it is exactly
It's not for fully qualified name, but for the file names. Because in the Surefire Plugin's document, I see usages like: |
Ok, that can work. Regardless, it just needs documenting well.
That to me sounds like a separate feature to filter by file path then, in which case glob patterns could be supported of course. Not sure it's strictly related to this PR, although it does raise the question of when/why would a user need to filter by file path if they can filter by pattern already? Something to think about... |
Good ask. To me it looks like pattern is enough. (Guess that's why IDEA only supports that) I don't know why the Surefire plugin supports both. But since there is a reference from IDEA, it makes me feel safer to move forward. To summary:
Sorry for having such a long discussion back and forth. Thanks for the patience. 👍 |
To clarify terminology here, is this more like inversion since we are dealing with a pattern, which can both include and exclude (without a {
"filters": {
"pattern": "!thisdoesntexist"
}
}
No worries! 🙂 I find this type of design discussion interesting! |
|
By the way, did you want to support multiple patterns for this feature? If so, I have a couple more implementation questions:
I don't personally have a use-case for multiple patterns at the moment, especially since a you can achieve simple conditional matching in a single regex pattern already: {
"filters": {
"pattern": "(TestClass|AnotherTestClass)"
}
}I do see it being useful in a couple of situations - for example, match every test in a class apart from one (although this might be possible still in a single pattern with a negative lookahead, albeit not the easiest expression to write): {
"filters": {
"patterns": [
"TestClass",
"!TestClass#testMethod"
]
}
} |
Let use
Instead of
Thank you for mentioning this! Negative lookahead can used for exclusion. And I noticed that this is exactly what IDEA does. So let's not bother using |
This reverts commit d3d224c.
If a user runs tests for a package from the test explorer view, doesn't it make sense to make the configuration available only if the pattern satisfies all test items (when running a package, each test item is a class)? That's what I meant by "every" - you could still define a single pattern that matches multiple items by itself (like in your example). |
|
I think things should work in the way that: User selects the configuration, the configuration filter the tests to execute. Not the selected tests determine which configurations should appear. |
That's not what I was intending this PR to address. From the original issue #1627:
For the class |
|
Ah, sorry I totally misunderstood the intension of the feature request. It's to filter the configurations to be displayed, not the tests to be executed. Since both IDEA and Surefire plugin has the capability to configure the pattern filter for test execution, how can we make sure users are aware the purpose of this setting? (At least, it confused me 😢) What I'm thinking right now is to put it into a new key, not the key Or just simply One question is: Currently there is only one condition - pattern match to determine if the configuration will be displayed or not. In the future, if one more condition appear, how to specify if it's an An answer could be referencing how VS Code handles such case: https://code.visualstudio.com/api/references/when-clause-contexts#match-operator. We can use something like
|
Yeah, I probably could have explained better, sorry - I thought we were on the same page! 😅
Yeah, I think you're right here. It is confusing that
I like that this could follow the VS Code when clause convention. We would have to parse the expression ourselves though, unless there's an API for that already...
I do like how explicit this is vs the when clause, but agreed that it could get complicated as soon as another condition is added. |
Let's go for the vscode when clause approach. WDYT? |
|
Yep, let's do it. 😄 |
… and match operator only
jdneo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @ReubenFrankel, some feedbacks added.
|
@jdneo I have been working on a utility class to evaluate a when-clause, since there is no equivalent public VS Code API (that I could find). Are you interested in that as part of this feature? Obviously, it will need some unit tests (which I did start writing) and a little more manual testing. |
Yeah, I like that! Thank you for the effort! |
90cc72f to
71c409c
Compare
71c409c to
53506ba
Compare
jdneo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, added some new comments.
|
I guess we can link off to the VS Code reference for the when-clause syntax now? The only features not supported by this implementation are the |
|
Appended a commit to add chinese description and did some simplification. I prefer to progressively adding more description on demand (if users are confused). So Let wait and see if we need to link to the VS Code reference for the when-clause syntax. |
jdneo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I'll wait if you have more comments on the appended commit. If not, I'll merge it.
Merry Christmas! 🎉
|
Last thing would maybe be to remove the bit of the description about the only supported clause ( Merry Christmas! 😁🎄 |
I tend to keep as what it is since |
|
Merged. Thank you @ReubenFrankel for your contribution. |

Closes #1627