【发布时间】:2019-03-09 22:27:17
【问题描述】:
Eclipse (2018-09) 仅当 JUnit 5 引擎存在于项目的类路径中时才支持 JUnit 5 测试。
现在我的 Maven 项目有两种可能性:
-
通过 Eclipse JUnit 库将其添加到项目中
并且只将 API 添加到依赖项
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <scope>test</scope> </dependency> -
将引擎和 API 添加到我的 Maven pom
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <scope>test</scope> </dependency>
如果我做前者,那么每个使用 eclipse 的人都必须自己做。
如果我做后者,那么我的(测试)编译时类路径会被实现类污染,我(和其他 IDE 的用户)可能会使用它来代替 API 类。此外,这可能会导致与可能需要不同版本引擎的 IDE 发生冲突,而不是 cp 上的版本。 IIRC 这就是 API 和引擎首先被拆分的全部原因。
不幸的是,Maven 中没有 testRuntimeOnly 范围(就像 gradle 中一样)。
TLDR:为 Maven 项目配置 JUnit 5 for eclipse 的正确方法是什么?
【问题讨论】: