簡體   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