java Intellij 不运行测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34303792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:43:34  来源:igfitidea点击:

Intellij does not run tests

javaintellij-idea

提问by mherzl

After importing my project into Intellij and getting it to build successfully, I am trying to run some of my project's tests. I navigate to the test file and select Run -> Run. However, this does not run my tests, just opens a small "Edit Configurations" window, as the attached photo shows.

将我的项目导入 Intellij 并使其成功构建后,我正在尝试运行我的一些项目测试。我导航到测试文件并选择运行 -> 运行。但是,这不会运行我的测试,只是打开一个小的“编辑配置”窗口,如所附照片所示。

enter image description here

在此处输入图片说明

And, when I select Edit Configurations as prompted, JUnit is not to be found. The window is shown below.

而且,当我按照提示选择“编辑配置”时,找不到JUnit。窗口如下所示。

enter image description here

在此处输入图片说明

What do I need to do to run the tests?

我需要做什么来运行测试?

回答by rayen

makre sure you IDEA have installed the Junit plugins and Junit jar in your classpath:enter image description here

确保你的 IDEA 已经在你的类路径中安装了 Junit 插件和 Junit jar:在此处输入图片说明

and then just click this place to run test case:

然后只需单击此位置即可运行测试用例:

enter image description here

在此处输入图片说明

回答by anon58192932

For me this was an issue with my pom.xmland using JUnit5with IntelliJbecause my tests were not getting detected and it said 0 executed 0 skippedetc.

对我来说,这是我的问题pom.xml,并使用JUnit5IntelliJ因为并没有获得检测我的测试中,它说0 executed 0 skipped等。

Here's what I added to my pom.xmlto get JUnit5tests to run in IntelliJ:

这是我添加到我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>

And here's the dependencies I added:

这是我添加的依赖项:

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

回答by Jac.

For me it was also an issue with my pom.xml. After checking Junit5-samples pom. I noticed the test plugin was missing. So I only needed to add:

对我来说,这也是我的 pom.xml 的问题。检查Junit5-samples pom 后。我注意到测试插件丢失了。所以我只需要添加:

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

You may also want to check if your pom contains:

您可能还想检查您的 pom 是否包含:

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

回答by Pablo Souza

Try to click on your project and click on Run 'All Tests'. After that, go to 'Edit Configurations..' and make sure you are using -eavalue on VM Options area.

尝试单击您的项目并单击Run 'All Tests'。之后,转到“编辑配置..”并确保您使用的-ea是 VM 选项区域上的值。

enter image description here

在此处输入图片说明