简体   繁体   English

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

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

I'm trying to introduce Unit tests to our system, and have run into a problem with Junit not finding test.我正在尝试向我们的系统引入单元测试,但遇到了 Junit 找不到测试的问题。 I have these 3 tests:我有这3个测试:

在此处输入图像描述

When I run all tests in the module:当我运行模块中的所有测试时:

在此处输入图像描述

It finds X and Y tests, but not Z:它找到 X 和 Y 测试,但没有找到 Z:

在此处输入图像描述

The difference between the 3 is only in the package name: 3者的区别仅在于package名称:

  • The package com.exlibris.x (XTest) doesn't exist in the project项目中不存在 package com.exlibris.x (XTest)
  • The package com.exlibris.core.infra.svc.api.flags (YTest) exists in a different module in the project (that is outputted to a different jar file) package com.exlibris.core.infra.svc.api.flags (YTest) 存在于项目的不同模块中(输出到不同的 jar 文件)
  • The package com.exlibris.repository.web.mms.publishing (ZTest) exists in the same module under the src/main/java package com.exlibris.repository.web.mms.publishing (ZTest)存在于src/main/java下的同一模块中

My pom.xml has the following dependencies (inherited from the parent pom):我的 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>

EDIT: These are my run configurations编辑:这些是我的运行配置

在此处输入图像描述

在此处输入图像描述

So it turned out there were a few issues (some of them are likely not related to the specific question, but still best practices).所以事实证明存在一些问题(其中一些可能与特定问题无关,但仍然是最佳实践)。 What helped for me was:对我有帮助的是:

  1. Consolidate dependency management of JUnit by importing junit-bom通过导入junit-bom统一JUnit的依赖管理
  2. Upgrading maven-surefire-plugin to latest version将 maven-surefire-plugin 升级到最新版本
  3. Removing unnecessary configs from maven-surefire-plugin (my configuration tag is now empty)从 maven-surefire-plugin 中删除不必要的配置(我的配置标签现在是空的)
  4. Reloading the project in IntelliJ (Right click project -> Maven -> Reload project)在 IntelliJ 中重新加载项目(右键单击项目 -> Maven -> 重新加载项目)

Thanks a lot to khmarbaise and Kathrin Geilmann for the help:)非常感谢khmarbaiseKathrin Geilmann的帮助:)

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

相关问题 JAVA - 无法将 src/test/java 导入 src/main/java - JAVA - can't import src/test/java to src/main/java 为什么我的java swing操作无法在src / main / resources中找到我的图像? - Why can't my java swing action find my image in src/main/resources? IntelliJ Ultimate无法在Play 2.3(Java)项目测试中找到路由 - IntelliJ Ultimate can't find routes in Play 2.3 (Java) project tests IntelliJ IDEA:库在src \\ test \\ java上可用,但在src \\ main \\ java上不可用 - IntelliJ IDEA: library available on src\test\java but not on src\main\java 两个 java 文件在同一个 package 但仍然出现错误找不到符号:class(使用 intellij IDE) - Two java files in same package but still getting error can't find symbol : class (using intellij IDE) Java 无法访问 src/main/resources 中的 txt 文件 - Java can't access txt file in src/main/resources Java 在资源文件夹 Intellij 中找不到解决方案 package - Java doesn't find solution package in resource folder Intellij 由于放置了包名,无法在 java 中找到或加载主类 - Could not find or load main class in java due to placing a package name 无法在 eclipse 中将 class src/test/java 导入 src/main/java - can't import class src/test/java into src/main/java in eclipse 无法从 src/main/java 调用 src/test/java 中的代码? - can't able to call code inside src/test/java from src/main/java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM