繁体   English   中英

如果 package 名称存在于 src/main/java 中,IntelliJ 无法找到测试

[英]IntelliJ can't find tests if package name exists in src/main/java

我正在尝试向我们的系统引入单元测试,但遇到了 Junit 找不到测试的问题。 我有这3个测试:

在此处输入图像描述

当我运行模块中的所有测试时:

在此处输入图像描述

它找到 X 和 Y 测试,但没有找到 Z:

在此处输入图像描述

3者的区别仅在于package名称:

  • 项目中不存在 package com.exlibris.x (XTest)
  • package com.exlibris.core.infra.svc.api.flags (YTest) 存在于项目的不同模块中(输出到不同的 jar 文件)
  • package 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. 通过导入junit-bom统一JUnit的依赖管理
  2. 将 maven-surefire-plugin 升级到最新版本
  3. 从 maven-surefire-plugin 中删除不必要的配置(我的配置标签现在是空的)
  4. 在 IntelliJ 中重新加载项目(右键单击项目 -> Maven -> 重新加载项目)

非常感谢khmarbaiseKathrin Geilmann的帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM