我的项目是使用 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 的示例,如果你向下滚动一点:
Using @RunWith(JUnitPlatform.class) will output all reported entries to stdout.
那为什么我的代码不能编译?我是不是误会了什么?
运行 gradlew 构建:
TestGameController.java:12: error: cannot find symbol
@RunWith(CacioTestRunner.class)
^
symbol: class RunWith
Run Code Online (Sandbox Code Playgroud)
JB Nizet 在他的评论中回答了我的问题。
RunWith 是 JUnit 4 注释。查看它的包:org.junit.runner.RunWith。包装内没有“木星”。JUnit 5 中的“等效项”是 ExtendWith,它需要 JUnit 5 扩展类作为参数。您需要添加对 JUnit 4 的依赖项,使用 JUnit 4 API 编写测试,并在没有 CacioExtension 类的情况下使用 JUnit 4 的老式引擎。
| 归档时间: |
|
| 查看次数: |
6803 次 |
| 最近记录: |