【发布时间】:2020-12-08 21:49:27
【问题描述】:
我正在将一个测试方法从单个参数修改为多个:
@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 这里是作为字符串文字而不是空文字传入的。结果,此测试失败。此测试之前使用 @NullSource 的单个参数,但切换到多个时会出现以下错误:
org.junit.jupiter.api.extension.ParameterResolutionException:没有为参数注册ParameterResolver ...
我找不到解决方法,而且我看到的解决方案相当笨拙和麻烦。有没有更简单的方法来提供 null 的值?
【问题讨论】: