繁体   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