从junit4迁移到junit5时,而不是
@Parameterized.Parameters
public static Collection input() {}我已经在所有的测试方法之前添加了
@ParameterizedTest
@MethodSource("input")但我得到的错误是: org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver为参数注册
任何帮助都很感激!
发布于 2022-01-21 10:16:50
参数化测试的正确实现示例:
//example with 2 parameters
@ParameterizedTest
@MethodSource("input")
void myTest(String input, String expectedResult) {
//test code
}
// Make sure to use the correct return type Stream<Arguments>
static Stream<Arguments> input() {
return Stream.of(
Arguments.of("hello", "hello"),
Arguments.of("bye", "bye")
//etc
);
}另外,请确保您使用的是一个兼容版本的junit:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${some.version}</version>
<scope>test</scope>
</dependency>此外,如果仍然有junit-vintage-engine测试,则需要junit4依赖项。
https://stackoverflow.com/questions/70799565
复制相似问题