-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
@ParameterizedTest
ignores additional arguments beyond formal parameter list
#3708
Comments
Hi @milliken99, Congratulations on opening your first issue on GitHub! 👍 Regarding your test setup, you have incorrectly created your stream of arguments. With the following, the 2nd invocation fails as expected. return Stream.of(Arguments.of("1"), Arguments.of("")); In light of that, I am closing this issue. |
Hi Sam, thanks for your comment. The incorrect stream of arguments was intentional. Since there are no suitable arguments for the indicated test method, I expected an error message. Instead I receive output that all tests pass. This is at best misleading. |
Oh. Then I wouldn't use Thus, if I understand you correctly, the following better illustrates your use case. private static Stream<Arguments> fooData() {
return Stream.of(Arguments.of("1", ""));
}
@ParameterizedTest
@MethodSource("fooData")
void testFoo(String fooString) {
assertFalse(fooString.isEmpty());
} That still ignores the Your For example, if you keep the above revised @ParameterizedTest
@MethodSource("fooData")
void testFoo(String str1, String str2) {
assertFalse(str1.isEmpty(), "str1");
assertFalse(str2.isEmpty(), "str2");
} That will then fail as follows.
In general, JUnit Jupiter's The code which implements this logic can be viewed here: junit5/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTestExtension.java Lines 152 to 158 in 264df92
Unfortunately, we cannot throw an exception in such cases since it's an existing feature that people depend on. Though I suppose it would be possible to introduce a flag ( Is that a feature that you would be interested in? |
@ParameterizedTest
ignores additional arguments beyond formal parameter list
I think we would be interested in this feature. Call it If we go this route, would it also be possible to set this globally in |
OK.
As we all know, "naming is hard" in computer science. 😉
If we want users to be able to change the default globally, we will have to introduce an enum (3 states: default/global, true, false) instead of using a simple boolean flag (2 states: true, false), but that's certainly an option. We'll discuss the topic it within the team during an upcoming team call. |
Team decision: Add |
Hey @marcphilipp @sbrannen could I work on this issue? Cheers |
@bottlerocketjonny Sure, go ahead! I've assigned the issue to you now. Please let us know if you need any help. |
Thanks! I'll take a look myself over the next week but if I get stuck I'll be in touch 👍🏻 |
@bottlerocketjonny are you still working on this? If not, I'd like to work on a PR for this feature. |
Hi! Life ended up getting in the way unfortunately so I didn't get far. Feel free to take the issue. |
@JonasJebing Any updates? Need any help? |
It doesn't seem too complicated so far. I just happen to be taking some
vacation but I am hoping to have at least a draft PR within 2 - 3 weeks
|
This allows parameterized tests to fail when there are more arguments provided than declared by the test method. This is done in a backwards compatible way by only enabling that validation when the new `junit.jupiter.params.argumentCountValidation` is set to `strict` or `ParameterizedTest#argumentCountValidation` is set to `ArgumentCountValidationMode.STRICT`.
This allows parameterized tests to fail when there are more arguments provided than declared by the test method. This is done in a backwards compatible way by only enabling that validation when the new `junit.jupiter.params.argumentCountValidation` is set to `strict` or `ParameterizedTest#argumentCountValidation` is set to `ArgumentCountValidationMode.STRICT`.
HIi @marcphilipp Is this issue still open? I see a PR to close this issue? |
Yes, it's still open because we haven't merged the PR, yet. 🙂 |
- add `writing-tests-parameterized-tests-argument-count-validation` section to the user guide. - cache configuration parameter in `ExtensionContext.Store` - adjust log and error messages Issue junit-team#3708
release-notes-5.12.0-M1-junit-jupiter-new-features-and-improvements to be exact Issue junit-team#3708
This should result in invocations with valid argument counts still being executed and only invocations with invalid argument counts fail. Issue junit-team#3708
junit-jupiter-params-5.9.2
Steps to reproduce
I would expect a runtime error as the stream of arguments return in
fooData()
aren't compatible withtestFoo(String s)
. In this instance, only the first argument (i.e."1"
) is fed totestFoo()
, all other arguments are unceremoniously dropped on the floor. Note that the second argument (i.e.,""
) is not tested and would have led to a unit test failure.Context
The text was updated successfully, but these errors were encountered: