java - 为什么使用 junit-jupiter (聚合器)执行测试而不使用单独的依赖项?
问题描述
我正在使用 Maven 构建一个 Spring Boot 项目。
当我像这样设置 Junit jupiter 依赖项时
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.5.1</version>
<scope>test</scope>
</dependency>
我得到了错误
七月 2019 年 2 月 23 日晚上 10:47:42 org.junit.platform.launcher.core.DefaultLauncher handleThrowable 警告:ID 为“junit-jupiter”的 TestEngine 未能发现测试 java.lang.NoClassDefFoundError:org/junit/platform/engine/support /发现/选择器解析器
但是当我使用聚合器设置依赖项时,测试会正常执行。
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.1</version>
<scope>test</scope>
</dependency>
那么这两者有什么区别呢?
解决方案
您缺少junit-platform-launcher
工件。请参阅官方 JUnit 5 用户指南:
JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage
您应该将此添加到您的pom.xml
:
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.5.2</version>
<scope>test</scope>
</dependency>
推荐阅读
- document - 在java中解析html文档
- php - 如果登录成功,如何使用 header() 函数重定向到索引?
- python - scikit-learn 中的负平均绝对误差是多少?
- python - 如何索引已变成列表的字典
- android - 通过意图 putString 将值传递给另一个活动正在使用 nullPointerException 使应用程序崩溃
- r - 如何将 ggplot 中的标签转换为 R?
- ms-access - 在 Access 中创建代理键
- amazon-web-services - 将 AWS S3 不频繁访问 (IA) 与云前端一起用于静态网站资源是否是一种好习惯?
- php - PHP / FB Graph:如何从消息对象访问消息文本?
- firebase - Firebase-tools 没有将新创建的函数上传到 Firebase