Question
Junit 5 - How to pass in multiple null values for @CsvSource?
I am modifying a test method from single parameter to multiple:
@ParameterizedTest
@NullSource
@ValueSource({"foo", "bar"..})
void shouldReturnFalse(String x) {
assertThat(someMethod(x)).isFalse();
}
@ParameterizedTest
@CsvSource({
"null, null",
"foo, bar"
})
void shouldReturnFalse(String x, String y) {
assertThat(someMethod(x, y)).isFalse();
}
null
here is passed in as a String literal instead of a null literal. As a result, this test fails. This test previously works with single argument with @NullSource
, but it gives following error when switched to multiple:
org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter...
I couldn't find a workaround for this and the solutions I saw were rather hacky and cumbersome. Is there a easier way for providing values with null
?