-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Introduce @BooleansSource
for use with @ParameterizedTest
#4507
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
Comments
@BooleansSource
for use with @ParameterizedTest
Hi @overwave, Thanks for the proposal, and congratulations on submitting your first issue for JUnit 5. 👍
No, that would not be possible. All of the attributes in As stated in the Javadoc:
Providing a However, it would be possible to introduce a dedicated argument source that always provides I have therefore changed the title of this issue to reflect that, and we will discuss the proposal within the team. Note, however, that Regards, Sam |
Such a boolean source can be implemented as a composed annotation as follows. @Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ValueSource(booleans = {true, false})
public @interface BooleansSource {
} And that can be used as follows. @ParameterizedTest
@BooleansSource
void test(boolean flag) {
assertTrue(flag || !flag);
} |
Hi, @sbrannen! Thanks for the reply. Yes, I understand the solution requires a new annotation, as both you and me proposed above. The request is to add such annotation (as you've mentioned) to the JUnit library so the code for The JUnit also has this verbose alternative: https://github.com/search?q=repo%3Ajunit-team%2Fjunit5%20%40ValueSource(booleans%20%3D%20%7B%20true%2C%20false%20%7D)&type=code I will understand if you decide to have more clean API rather than many shortcuts, but this could make our code (and I think someone's too) a little bit tidier. Best regards, |
Hi @sbrannen, @marcphilipp and the rest of JUnit Team, I hope this message finds you well. I am still very enthusiastic about contributing to this enhancement and am eager to implement the feature if it aligns with your future plans for JUnit. Please let me know if this proposal is under consideration or if there is any additional information or assistance I can provide to help move this forward. Thank you for your attention to this matter. I appreciate the work you do to make JUnit a robust and user-friendly testing framework, and I hope to contribute to this effort. Looking forward to your feedback. Best regards, |
@overwave I like your enthusiasm! 🙂 However, as stated in #4518 (comment), we first need to discuss whether we want to add this feature in the team before reviewing a potential solution. We'll post here when that has happened. |
Team decision: Since |
Uh oh!
There was an error while loading. Please reload this page.
Our team extensively utilizes JUnit Jupiter, particularly the
@ParameterizedTest
feature, to streamline our testing processes.A common pattern we have observed involves the use of the
@ValueSource
annotation with thebooleans
attribute. Typically, this attribute is used to check whether our code behaves consistently when a feature flag is enabled versus when it is not. Consequently, the majority of our tests require a boolean array containing bothtrue
andfalse
values.To address this need, we have developed several custom annotations that utilize
@ValueSource(booleans = {true, false})
. However, we believe this pattern is prevalent enough to warrant inclusion in the standard library, reducing redundancy and simplifying test code across projects.Would it be possible to consider adding a default boolean array
{true, false}
option for the@ValueSource
annotation in future JUnit releases? We believe this addition would benefit many users by eliminating the need to create custom annotations for such a common use case.I can implement the feature myself, it it would be any help to this.
Thank you for your consideration of this proposal. I look forward to any feedback or questions you might have.
Rodion.
The text was updated successfully, but these errors were encountered: