簡體   English   中英

Intellij 不運行測試

[英]Intellij does not run tests

將我的項目導入 Intellij 並使其成功構建后,我正在嘗試運行我的一些項目測試。 我導航到測試文件並選擇運行 -> 運行。 但是,這不會運行我的測試,只是打開一個小的“編輯配置”窗口,如所附照片所示。

在此處輸入圖片說明

而且,當我按照提示選擇“編輯配置”時,找不到JUnit。 窗口如下所示。

在此處輸入圖片說明

我需要做什么來運行測試?

確保你的 IDEA 已經在你的類路徑中安裝了 Junit 插件和 Junit jar: 在此處輸入圖片說明

然后只需單擊此位置即可運行測試用例:

在此處輸入圖片說明

對我來說,這是我的pom.xml和將JUnit5IntelliJ一起使用的問題,因為我的測試沒有被檢測到,它說0 executed 0 skipped等。

這是我添加到我的pom.xml以使JUnit5測試在IntelliJ運行的內容:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.2.0-M1</version>
                </dependency>
                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <version>5.2.0</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

這是我添加的依賴項:

    <dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.2.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.easytesting</groupId>
        <artifactId>fest-assert-core</artifactId>
        <version>2.0M10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-surefire-provider</artifactId>
        <version>1.2.0-M1</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.2.0-M1</version>
    </dependency>
</dependencies>

對我來說,這也是我的 pom.xml 的問題。 檢查Junit5-samples pom 后 我注意到測試插件丟失了。 所以我只需要添加:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.2</version>
</plugin>

您可能還想檢查您的 pom 是否包含:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>5.6.2</version>
    <scope>test</scope>
</dependency>

嘗試單擊您的項目並單擊Run 'All Tests' 之后,轉到“編輯配置..”並確保您在 VM 選項區域使用-ea值。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM