junit 如果src/main/java中存在包名称,则IntelliJ找不到测试

oalqel3c  于 2023-01-30  发布在  Java
关注(0)|答案(1)|浏览(134)

我试图在我们的系统中引入单元测试,但遇到了一个问题,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>

编辑:这些是我的运行配置

zmeyuzjn

zmeyuzjn1#

结果发现有几个问题(其中一些可能与具体问题无关,但仍然是最佳实践)。
1.通过导入junit-bom合并JUnit的依赖关系管理
1.正在将maven-surefire-plugin升级到最新版本
1.从maven-surefire-plugin中删除不必要的配置(我的配置标签现在是空的)
1.在IntelliJ中重新加载项目(右键单击项目-〉Maven -〉重新加载项目)
非常感谢khmarbaiseKathrin Geilmann的帮助:)

相关问题