You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I have a parameterized test, and each parameter is a List of Beans where each bean represents a line in a csv file (opencsv). What I want for the actual "parameterized name" is the filename.
I had the exact same use case not long ago, and I ended up passing the name as an argument like you did. I agree that it's not ideal...
That being said, I'm not sure how your solution whould deal with the name attribute of @ParameterizedTest? Would the name provided in Arguments replace it? Would you be able to insert it in the name with a placeholder like the other arguments?
I think in the proposed solution it would replace it, though you could also do that latter, I'm not certain on the right answer there. TBH I'm not even certain the proposed answer is the right answer.
no, seems completely unrelated, since mine was about having to receive a parameter that I'm not using at all, other than to go into the test name. That would still be true even if the parser was improved. #1154 is still a great idea though. Thing is, in my example filename isn't in the array at all, it serves no real purpose other than to describe the file that I'm reading
Team decision: Add a Named<T> interface in junit-jupiter-api and add automatic support for injecting the contained payload into parameterized methods directly.
Activity
juliette-derancourt commentedon May 15, 2020
I had the exact same use case not long ago, and I ended up passing the name as an argument like you did. I agree that it's not ideal...
That being said, I'm not sure how your solution whould deal with the
name
attribute of@ParameterizedTest
? Would the name provided inArguments
replace it? Would you be able to insert it in thename
with a placeholder like the other arguments?xenoterracide commentedon May 15, 2020
I think in the proposed solution it would replace it, though you could also do that latter, I'm not certain on the right answer there. TBH I'm not even certain the proposed answer is the right answer.
juliette-derancourt commentedon May 15, 2020
Personally I think I'd prefer the latter.
But I'm not sure it would be useful outside of this (pretty rare) use case... Unless you see other ones?
Well I guess there is no right answer anyway 🤓
juliette-derancourt commentedon May 22, 2020
I think the request in #1154 would also solve your problem, wouldn't it?
xenoterracide commentedon May 22, 2020
no, seems completely unrelated, since mine was about having to receive a parameter that I'm not using at all, other than to go into the test name. That would still be true even if the parser was improved. #1154 is still a great idea though. Thing is, in my example filename isn't in the array at all, it serves no real purpose other than to describe the file that I'm reading
xenoterracide commentedon May 22, 2020
Actually I might have described my proposed solution poorly, a better Api might be something like (obviously some pseudocode)
Arguments.of( Argument.of(filename, passAsArgument = false ))
then it wouldn't actually pass that first argument to the method signature, but it would still be passed to the description.
this is a pretty minor problem though.
marcphilipp commentedon Jun 8, 2020
How about a simple
Named<T>
object that wraps the argument?xenoterracide commentedon Jun 8, 2020
personally not opposed
juliette-derancourt commentedon Jun 14, 2020
I like the idea! 👍
sbrannen commentedon Aug 7, 2020
Tentatively slated for 5.8 Backlog to be considered in conjunction with #2375.
5 remaining items
marcphilipp commentedon Sep 25, 2020
Team decision: Add a
Named<T>
interface in junit-jupiter-api and add automatic support for injecting the contained payload into parameterized methods directly.thomasdarimont commentedon Oct 2, 2020
This could be really useful when replicating Go style table-driven tests with
DynamicTests
and local records from Java 15.See: https://twitter.com/thomasdarimont/status/1312100991127285760
With the
Named
interface from above, one could reduce the plumbing for this a bit.Btw. if the
DisplayName
annotation were a bit more flexible one could do something like this:Here is a gist with some more examples: https://gist.github.com/thomasdarimont/1650ab4d914072bb32d32b58a9ccc571
FlorianCousin commentedon Nov 19, 2021
What if we have several parameters in a test as follows ?
For such a test, I would get my parameters as follows :
It seems that I cannot write
Is there any trick I missed ?
marcphilipp commentedon Nov 21, 2021
Named
allows you to override the name of one argument.Hence, you could do
and then use the
name
attribute in order to use that name to describe the entire invocation:FlorianCousin commentedon Nov 21, 2021
I see, thank you @marcphilipp.
@ParameterizedTest
#3818