6

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.

enter image description here

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

enter image description here

What do I need to do to run the tests?

mherzl
  • 5,624
  • 6
  • 34
  • 75
  • Are your tests actually inside of a Test Source folder? – Makoto Dec 16 '15 at 04:14
  • 1
    Please review [this SO post](http://stackoverflow.com/questions/4757800/configuring-intellij-idea-for-unit-testing-with-junit). I'm guessing your IntelliJ cannot find the JUnit JAR, and this is why it is not appearing in the drop down (it appears in mine). – Tim Biegeleisen Dec 16 '15 at 04:14
  • Check in Project settings -> Modules that you test package is marked as Tests. – Rufi Dec 16 '15 at 07:19
  • Right click on the test class name either in the code window or in the project panel, and select Run . If you don't see the run menu in the popup then you haven't selected a test or you don't have junit plugin installed. – Software Engineer Dec 21 '15 at 12:48

4 Answers4

2

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>
Neuron
  • 5,141
  • 5
  • 38
  • 59
Jac.
  • 21
  • 2
1

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>
fIwJlxSzApHEZIl
  • 11,861
  • 6
  • 62
  • 71
0

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.

enter image description here

Pablo Souza
  • 863
  • 2
  • 11
  • 25
0

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

and then just click this place to run test case:

enter image description here

rayen
  • 89
  • 7