1

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.

1 Answer 1

1

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().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.