相当于 JUnit5 的 @RunWith(JUnitPlatform.class)

Szy*_*Żak 8 java migration junit junit4 junit5

在我的项目中,我正在做一些清理工作并决定将所有内容移至 JUnit5。

到目前为止,我一直在使用

@RunWith(JUnitPlatform.class)
Run Code Online (Sandbox Code Playgroud)

现在我想将它迁移到@ExtendWith。这个 JUnitPlatform.class 在 JUnit5 中是否有任何等价物?

Dri*_*ren 11

使用junit 5时不再需要它。

junit文档中,它指出:

使用 @RunWith(JUnitPlatform.class) 注释一个类允许它与支持 JUnit 4 但尚不直接支持 JUnit 平台的 IDE 和构建系统一起运行。

因此,由于您要迁移到 junit 5,我想您的构建系统/IDE 支持它。因此,您不再需要注释。

  • 那么如果我想用 Robolectric 运行 Android 项目测试我该怎么办?我通常会做 `@RunWith(RobolectricTestRunner::class)` (2认同)

Ced*_*rix 9

从https://www.baeldung.com/junit-5-runwith的内容开始,JUnit4@RunWith已被 JUnit5 取代@ExtendWith