gpt4 book ai didi

java - @RunWith 未在 JUnit5 中编译

转载 作者:行者123 更新时间:2023-12-05 02:10:15 26 4
gpt4 key购买 nike

我的项目是用 JUnit 5 设置的,我想为我的测试使用不同的 Runner,但我什至不能使用 @RunWith 注释,因为它无法编译。在本指南中,https://www.baeldung.com/junit-5-runwith ,它说 RunWith 应该仍然可以在 JUnit 5 中工作,所以我很困惑为什么它甚至不能编译。
https://junit.org/junit5/docs/current/user-guide/#writing-tests-dependency-injection如果你向下滚动一点,有一个使用 RunWith 的例子:
使用@RunWith(JUnitPlatform.class) 会将所有报告的条目输出到标准输出。
那么为什么我的代码不能编译呢?我是不是误会了什么?

运行 gradlew 构建:

TestGameController.java:12: error: cannot find symbol
@RunWith(CacioTestRunner.class)
^
symbol: class RunWith

最佳答案

JB Nizet 在评论中回答了我的问题。

RunWith is a JUnit 4 annotation. See its package:org.junit.runner.RunWith. There is no "jupiter" in the package. The"equivalent" in JUnit 5 is ExtendWith, which expects a JUnit 5extension class as argument. You'll need to add a dependency on JUnit4, write the test with the JUnit 4 API, and use the vintage engine ofJUnit 4 if there is no CacioExtension class.

关于java - @RunWith 未在 JUnit5 中编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58964654/

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