简体   繁体   中英

Intellij does not run tests

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.

在此处输入图片说明

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

在此处输入图片说明

What do I need to do to run the tests?

makre sure you IDEA have installed the Junit plugins and Junit jar in your classpath: 在此处输入图片说明

and then just click this place to run test case:

在此处输入图片说明

For me this was an issue with my pom.xml and using JUnit5 with IntelliJ because my tests were not getting detected and it said 0 executed 0 skipped etc.

Here's what I added to my pom.xml to get JUnit5 tests to run in 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>

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:

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

You may also want to check if your pom contains:

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

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

在此处输入图片说明

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