Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multiple parameters to @ValueSource

I'm trying to perform a parametrized JUnit 5 test, how to accomplish the following?

@ParametrizedTest
@ValueSource //here it seems only one parameter is supported
public void myTest(String parameter, String expectedOutput)

I know I could use @MethodSource but I was wondering if in my case I just need to understand better @ValueSource.

like image 419
Phate Avatar asked Mar 21 '26 22:03

Phate


1 Answers

The documentation says:

@ValueSource is one of the simplest possible sources. It lets you specify a single array of literal values and can only be used for providing a single argument per parameterized test invocation.

Indeed you need to use @MethodSource for multiple arguments, or implement the ArgumentsProvider interface.

like image 143
Vangelisz Ketipisz Avatar answered Mar 24 '26 16:03

Vangelisz Ketipisz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!