0

Very similar to [how to pass multiple null value for CSVSource]Junit 5 - How to pass in multiple null values for @CsvSource?

I am modifying a test method from single parameter to multiple:

@ParameterizedTest
@NullAndEmptySource
@MethodSource("generateData")
void testSomeMethod(String x,List<String> list) {
  doSomethingwith(x);
  doAnotherThingWith(list);
}

private static Stream<Arguments> generateData() {
    return Stream.of(
        Arguments.of("a", Arrays.asList("1","2","3")),
        Arguments.of("b", Arrays.asList("1","2","3")),
        Arguments.of("foo", Arrays.asList("1","2","3"))
    );
}

null and empty testcase added by this annotation @NullAndEmptySource failed with a ParameterResolutionException:No parameter registered for parameter [java.util.List<java.lang.String> arg1 in method [public void my.pachage.myclass.testSomeMethod]

Could anyone please guide me to pass the test case? I have no idea whether parameters matches because there are two parameters in the method and I don't understand what does the error message mean.

Shengxin Huang
  • 647
  • 1
  • 11
  • 25

1 Answers1

0

This error is encountered because @NullAndEmptySource is used on a method with more than one parameter (I tested it locally).
To pass the test, you should probably add the null and empty test cases in the stream returned by generateData().

AmeyaS
  • 36
  • 7