简体   繁体   中英

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. I have these 3 tests:

在此处输入图像描述

When I run all tests in the module:

在此处输入图像描述

It finds X and Y tests, but not Z:

在此处输入图像描述

The difference between the 3 is only in the package name:

  • The package com.exlibris.x (XTest) doesn't exist in the project
  • 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)
  • The package com.exlibris.repository.web.mms.publishing (ZTest) exists in the same module under the src/main/java

My pom.xml has the following dependencies (inherited from the parent 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
  2. Upgrading maven-surefire-plugin to latest version
  3. Removing unnecessary configs from maven-surefire-plugin (my configuration tag is now empty)
  4. Reloading the project in IntelliJ (Right click project -> Maven -> Reload project)

Thanks a lot to khmarbaise and Kathrin Geilmann for the help:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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