我试图在我们的系统中引入单元测试,但遇到了一个问题,Junit找不到测试。我有以下3个测试:
当我运行模块中的所有测试时:
它查找X和Y测试,但不查找Z:
3之间的区别仅在于包名:
- 项目中不存在包
com.exlibris.x
(XTest - 包
com.exlibris.core.infra.svc.api.flags
(YTest)存在于项目的不同模块中(输出到不同的jar文件) - 包
com.exlibris.repository.web.mms.publishing
(ZTest)存在于src/main/java下的同一模块中
我的pom.xml有以下依赖项(继承自父pom):
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
编辑:这些是我的运行配置
1条答案
按热度按时间zmeyuzjn1#
结果发现有几个问题(其中一些可能与具体问题无关,但仍然是最佳实践)。
1.通过导入junit-bom合并JUnit的依赖关系管理
1.正在将maven-surefire-plugin升级到最新版本
1.从maven-surefire-plugin中删除不必要的配置(我的配置标签现在是空的)
1.在IntelliJ中重新加载项目(右键单击项目-〉Maven -〉重新加载项目)
非常感谢khmarbaise和Kathrin Geilmann的帮助:)