gpt4 book ai didi

mockito - 使用@ParameterizedTest 和@RunWith(Parameterized.class) 时出现JUnit5(Vintage)初始化错误

转载 作者:行者123 更新时间:2023-12-05 08:31:48 26 4
gpt4 key购买 nike

我在尝试使用 JUnit 5 的参数化功能时偶然发现了一个初始化错误。

@ExtendWith(MockitoExtension.class)
@RunWith(Parameterized.class)
public class ServiceTest {

@InjectMocks
Service service;

private static Stream<Arguments> getArguments() {
return Stream.of(
Arguments.of("something", "result1", "result2"),
Arguments.of("another", "result3", "result4")
);
}

@ParameterizedTest
@MethodSource("getArguments")
@DisplayName("Test parseEndpoint method")
void testMethod(String arg1, String result1, String result2) {

final String[] strings = service.doSomething(arg1);

assertEquals(result1, strings[0]);
assertEquals(result2, strings[1]);
}

}

然后我可以看到我的测试正在由参数化引擎和 JUnit Vintage 单元运行。这里的问题是如何禁止这样的类仅由 Parameterized.class 运行?!

最佳答案

您在同一个类中混合使用 JUnit 4 和 5。

删除@RunWith(Parameterized.class),你不需要它。删除来自 junit 4 包的所有其他代码,如果有的话。

在那之后你的测试就没问题了。

关于mockito - 使用@ParameterizedTest 和@RunWith(Parameterized.class) 时出现JUnit5(Vintage)初始化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55415996/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com