-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add extension to disable per test name to be able to disable parameterized tests #175
Conversation
Sorry @nishantvas, I didn't have time to look at this and I'm pretty busy the next weeks. I will get to it eventually, I promise! :) |
I didn't really add this to be merged (yet) it was more to indicate the Idea I was trying to indicate with my Issue |
Hey @nishantvas, this is a pretty cool proof-of-concept! I wasn't aware that the conditional extension is executed for each parameterized test run - very clever to make use of that and the test display name. 👍 Keep working on it, it is definitely going into the right direction. |
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.
Just a quick comment. Let me know when you fleshed it out and are interested in a detailed review.
src/main/java/org/junitpioneer/jupiter/DisableIfNameExtension.java
Outdated
Show resolved
Hide resolved
Of course we still need examples, documentation, and commit message. In case you prefer only writing the code, that's ok as well, just let me know. |
One more note, should it be |
I vote for this so it's clear by the annotation name that the display name is taken into account and not the "coded name" |
Want to add Javadoc at least for the annotation interface |
Sure, makes sense and is more readable. I can also work on finalising this(the code is more of less in it's final form) and add more examples, documentations. How do you mean commit messages? Should I renamed the current commit messages? Is there any standard format? |
… into parameterized
That would be great!
Only the text for the final commit is needed as all the previous commits will get squashed while merging the branch into master - most probably done by @nicolaiparlog when you call it finished. |
Great, let me know when you're done and I'll review the PR then.
As Bukama mentioned, all commits will be squashed into one and then applied to master. That commit's message has a standard format, yes. You can propose a message if you want or I can write it if you prefer - your choice. :) |
I've added documentation and some more examples. Also updated the extension's name It made more sense to be able to have control to disable multiple tests in a set of Parameterized tests. Unfortunately, I'll be away for a while (PC access) @nicolaiparlog , @Bukama If there is something amiss, it's perfectly fine if you guys want to pick that up.. Otherwise, i can take care of it next week or so. |
… into parameterized
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.
Some minior improvement suggestions. Please take a look at them :)
docs/disable-if-display-name.adoc
Outdated
@@ -0,0 +1,42 @@ | |||
:page-title: @DisableIfDisplayName | |||
:page-description: JUnit Jupiter extensions to selectively disable Parameterized tests |
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.
(multiple) Parameterized ==> parameterized
docs/disable-if-display-name.adoc
Outdated
:page-title: @DisableIfDisplayName | ||
:page-description: JUnit Jupiter extensions to selectively disable Parameterized tests | ||
|
||
The `@DisableIfDisplayName` annotation Junit Jupiter extension that can be selectively used to disable Parameterized tests which are dynamically registered on runtime basis their display name. |
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.
This reads wired. What about this:
The
@DisableIfDisplayName
annotation can be used to selectivevly disable parameterized....
docs/disable-if-display-name.adoc
Outdated
The `@DisableIfDisplayName` annotation Junit Jupiter extension that can be selectively used to disable Parameterized tests which are dynamically registered on runtime basis their display name. | ||
The annotations is only supported on test method level for Parameterized tests. | ||
Unlike the `@Disabled` API provided in Junit which disables the test on first encounter of the annotation | ||
`@DisableIfDisplayName` is validated before each `@ParameterizedTest` so that each test (name) can be individually evaluated |
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.
Missing .
at the end of the sentence.
docs/docs-nav.yml
Outdated
@@ -16,3 +16,5 @@ | |||
url: /docs/temp-directory/ | |||
- title: "Vintage @Test" | |||
url: /docs/vintage-test/ | |||
- title: "@DisableIfDisplayName" |
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.
Please move up so it's sorted in alphabetically order
|
||
/** | ||
* {@code @DisableIfDisplayName} is a JUnit Jupiter extension which can be used to | ||
* selectively disable {@link ParameterizedTest} basis their {@link ExtensionContext#getDisplayName()} |
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.
basis their
Do you mean based on their
?
* If it is required that we wish to disable selective tests out of the plethora of dynamically | ||
* registered Parameterized tests, then we can utilize the following | ||
* | ||
* Each repeatable annotation will be processed for each test, and Test will be skipped if |
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.
and the test will be
* registered Parameterized tests, then we can utilize the following | ||
* | ||
* Each repeatable annotation will be processed for each test, and Test will be skipped if | ||
* any of them evaluate to be true against the display name |
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.
evaluates true against the display name.
@ExtendWith(DisableIfNameExtension.class) | ||
public @interface DisableIfDisplayName { | ||
|
||
/** |
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.
Displaynames of the tests cases to be disabled. The whole test case name can be stored as well as sub strings of it. The values will be evaluated [...] by default.
If {code regex} is provided, the string will be evaluated as ... display name.
@return Test case display name
/** | ||
* @return if the {@code value} is to be evaluated as regular expression or sub-string | ||
*/ | ||
boolean regex() default false; |
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.
Suggest to rename it to isRegEx
. The name regex
suggests that this field holds the regular expression itselfs, which will be confusing as a boolean
can't hold such.
} else { | ||
toDisable = context.getDisplayName().contains(details.value()); | ||
|
||
Optional<DisableIfDisplayName> disableIf = findAnnotation(testMethod, DisableIfDisplayName.class); |
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.
Please update to the new methods, provided by #187 after it is merged
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.
Will wait for #187 to be merged to resolve all the other comments then
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.
We just merged it, @nishantvas.
Since @Bukama already a close look at this, I'm gonna abstain until his comments were addressed. Let me know when that's done, so I can give a final review. |
Hey @nishantvas, |
Hi @Bukama, apologies I've been occupied in some other things. And didn't have access to my PC. |
Everything fine, take your time! |
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.
Thanks for the update. Just some small typos to correct and I would call this fine 👍
src/main/java/org/junitpioneer/jupiter/DisableIfDisplayName.java
Outdated
Show resolved
Hide resolved
|
||
/** | ||
* {@code @DisableIfDisplayName} is a JUnit Jupiter extension which can be used to | ||
* selectively disable {@link ParameterizedTest} based on their {@link ExtensionContext#getDisplayName()} |
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.
* selectively disable {@link ParameterizedTest} based on their {@link ExtensionContext#getDisplayName()} | |
* selectively disable {@link ParameterizedTest} based on their {@link ExtensionContext#getDisplayName()}. |
* selectively disable {@link ParameterizedTest} based on their {@link ExtensionContext#getDisplayName()} | ||
* | ||
* <p> | ||
* The extension is an {@link ExecutionCondition} which validates dynamically registered tests |
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.
* The extension is an {@link ExecutionCondition} which validates dynamically registered tests | |
* The extension is an {@link ExecutionCondition}, which validates dynamically registered tests. |
* This is highly useful since current {@link Disabled} or {@link DisabledIf} annotations disable | ||
* the whole test but not the Parameterized tests selectively |
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.
* This is highly useful since current {@link Disabled} or {@link DisabledIf} annotations disable | |
* the whole test but not the Parameterized tests selectively | |
* This is highly useful since current {@link Disabled} or {@link DisabledIf} annotations disable | |
* the whole test, but not the Parameterized tests selectively. |
* the whole test but not the Parameterized tests selectively | ||
* | ||
* If it is required to disable selective tests out of the plethora of dynamically | ||
* registered Parameterized tests, then we can utilize the following |
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.
* registered Parameterized tests, then we can utilize the following | |
* registered Parameterized tests, then we can utilize the following. |
* Each repeatable annotation will be processed for each test and test will be skipped if | ||
* any of them evaluates true against the display name |
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.
* Each repeatable annotation will be processed for each test and test will be skipped if | |
* any of them evaluates true against the display name | |
* Each repeatable annotation will be processed for each test and the test will be skipped if | |
* any of them evaluates true against the display name. |
* Display names of the test cases to be disabled. The whole test case name can be passed as well as sub string | ||
* The values will be evaluated with {@link String#contains(CharSequence)} by default |
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.
* Display names of the test cases to be disabled. The whole test case name can be passed as well as sub string | |
* The values will be evaluated with {@link String#contains(CharSequence)} by default | |
* Display names of the test cases to be disabled. The whole test case name can be passed as well as a sub string. | |
* The values will be evaluated with {@link String#contains(CharSequence)} by default. |
Co-Authored-By: Matthias Bünger <Bukama@users.noreply.github.com>
…ioneer into parameterized � Conflicts: � src/main/java/org/junitpioneer/jupiter/DisableIfDisplayName.java
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.
Thanks!
@Bukama, thanks for the proof checking. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs |
Thanks @nishantvas for the extension, this is really nifty. I added a bunch of changes to the PR, most notably that we can now distinguish between deactivating the test container and the individual invocations. While the code looked like it checked that (with
|
if (!context.getUniqueId().contains("test-template-invocation"))
return enabled("Never disable parameterized test method itself"); This does look relatively neater than using the Also, the Also, not using the keyword |
Kudos, SonarCloud Quality Gate passed! 0 Bugs |
Regarding my two points:
If nobody requires any further changes, I'm ok with this as it is and we can merge it. (Finally, sorry for taking so long with this.) Proposed commit message:
|
As said in stream chat I agree with Pioneer. So I'm fine with the current state of the PR too. |
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.
(Renewing acceptance)
Yea the code change seems perfectly alright. The run time check for no values with annotation usage is quite alright. As long as it's documented. Otherwise it can be a tad misleading. But I'm happy with this. Thanks for the changes |
Additional extension to be able to skip tests based on test name
This is particularly helpful when dealing with Parameterized or Dynamically Registered tests
#163
I hereby agree to the terms of the JUnit Pioneer Contributor License Agreement.