Intellij Right click on a test does not present a "Run" option

Intellij Idea

Intellij Idea Problem Overview


In IntelliJ when I right click on a test I dont see a "Run ClassX or MethodY" anymore. Infact there is no "run" window and when I right click I cannot run any class.

It was all working fine about 3 hours ago so I am not quite sure what has changed?

IntelliJ 10.5.1 (Licensed and NOT community edition) Java 1.6.0_24

Is there anyone who could help me with this? PS: This happens for all projects.

UPDATE 1 I installed IDEA 11 and imported settings from 10 and then saw that it was not a free upgrade close IDEA 11 and started using IDEA 10. I am fairly certain things stopped working from that point but not sure. Is that a problem? Can I somehow delete IntelliJ configuration directory somehow and restart?

Adding a screenshot when I dont get Run option on right click enter image description here

Intellij Idea Solutions


Solution 1 - Intellij Idea

If your project is a maven project then you can just right-click on the pom.xml file and select "add as Maven project".

This approach worked for me. (green plus third from the bottom)

enter image description here

Solution 2 - Intellij Idea

My problem was that my test class wasn't public. I needed:

public class MyTest {

    @Test
    public void testMethod() {

instead of:

class MyTest {

    @Test
    void testMethod() {

Solution 3 - Intellij Idea

I had the same problem. To fix it, I had to ensure that my class had a proper main method:

public static void main(String[] args) {
}

I had forgotten the arguments in mine ;-)

EDIT: Make sure your source codes are inside a src folder.

Solution 4 - Intellij Idea

In my case, the cause was disabled JUnit plugin. (File — Settings — Plugins — JUnit, check, OK)

Solution 5 - Intellij Idea

If you're using JUnit 5 (Jupiter), this happens when you use the old @Test annotation from JUnit 4. Just replace

import org.junit.Test;

with

import org.junit.jupiter.api.Test;

and IntelliJ should show the "Run" button again.

Solution 6 - Intellij Idea

Ok after tremendous amount of eyeballing I located a {HOME}/.java directory which seemed to contain some Jetbrains related preferences. I deleted that directory plus {HOME}/.IntelliJ* directories. Then deleted all my intellij installations and downloaded it again from scratch and it now works fine..

Sigh....

Solution 7 - Intellij Idea

Disabling gradle plugin solved the issue for me (community edition 2018.2)

Solution 8 - Intellij Idea

In my case i right clicked the src folder and went to -> mark directory as -> sources root.

Solution 9 - Intellij Idea

There should be no need to delete any configuration files.

I found that I used to have the Run option in the context menu to select either run tests or run Scala tests, etc. After I had selected an option for the first time, my options were no longer there.

I was able to resolve this issue and select the type of tests I wanted for that folder by creating a Run/Debug configuration following the instructions found in the documentation here...

https://www.jetbrains.com/help/idea/2016.1/creating-run-debug-configuration-for-tests.html?origin=old_help

Solution 10 - Intellij Idea

As i had the same issue , i could clearly See that @Test is not providing any hint when i press control key and hover , and the same was confirmed as External Libraries was not having Gradle Dependencies added so i had to update the project as gradle project suggested by a pop up when you start Intellij.

Solution 11 - Intellij Idea

I had the same problem. I solve it by File -> Invalidate Caches / Restart right click on the top pom.xml -> Maven -> reimport enter image description here

Solution 12 - Intellij Idea

I've just had the same problem and solved it in the following way.

Go to your $USER/$INTELLIJ directory e.g. $USER/.IdeaC2018.3 then find config/plugins. Rename the plugins directory and restart IntelliJ.

My guess is that the problem was caused when I upgraded IntelliJ and incompatibilities with the cucumber plugin.

Solution 13 - Intellij Idea

For me this happened after updating Idea, and then updating all Plugins. Apparently Idea had not restarted yet. Going to File -> Settings -> Plugins and clicking 'Restart Idea' solved the problem

Solution 14 - Intellij Idea

if you can see the play button in left side of the main function then click right click and press run.

Solution 15 - Intellij Idea

in my case, I did not have an output folder. file -> project structure -> under 'project' tab there's 'Project compiler output' -> define your folder.

Solution 16 - Intellij Idea

I could resolve the issue by disabling the Gradle plugin from the Plugin menu and restart.

Solution 17 - Intellij Idea

Unfortunately, none of these worked for me. I had to

  1. 'File' -> "Invalidate Caches / Restart"

  2. Click on pom.xml file, and then 'maven' -> "Generate Sources" maven, generate sources

Solution 18 - Intellij Idea

If the project is already added as a Maven one, unlink it.

right click on the project -> Maven -> Unlink Maven Projects

Then link it again:

right click on pom.xml -> + Add as Maven Project

Solution 19 - Intellij Idea

So I had this problem on pycharm and the problem was that there was already a run configuration (in the dropdown next to the play button) that had the name of the file. When i deleted that run configuration it would create a new one that was correct.

Solution 20 - Intellij Idea

I had the same problem and I tried all the above solutions nothing worked for me but after I install TestNG plugin it's started working since there are some TestNG annotations used in my unit tests

Solution 21 - Intellij Idea

I had the same problem on my Intellij 2019.3 after that I updated from 2019.2.4. I thought that the problem came from the updated first, but the rollback didn't fix, so I tried de solution above e the problem was fixed. After configuring all my projects from scratch the problem get back, so I started to check everything I did. I discovered that an old project from Eclipse that uses files .launch to run and need some plugins to be able to execute on Intellij was causing the problem, after disable the following plugins the test option return.

plugins

Solution 22 - Intellij Idea

In my case, my project is using Bazel.

The solution was to sync Bazel from Bazel plugin.

Solution 23 - Intellij Idea

Since this is a top Google result when trying to figure out how to run a Scala project, and since for some reason IntelliJ (I'm on 2020.1.2) doesn't automatically create a run configuration for a Scala project (in contrary to a Java project), it's worth laying out the basics for future readers:

  1. Click on "Edit Configuration" on the top right of the screen.
  2. Inside the opened window, click the + button its top left.
  3. Choose "Application".

Now, let's go through the required fields:

  1. in the "Name" field, enter a name for this configuration, e.g. "run".
  2. in the "Main Class" field, enter your main class name.
    Alternatively, use the ... button to the left: inside the window that opens, click the "Project" tab, navigate to your main class, pick it and click "ok".
    Note: If your main class doesn't have a main method, IntelliJ would show an alert. see listing 9 below.
  3. Make sure the value in "Working Directory" field is correct (it should be the project folder).
  4. in "Use classpath of module", select your module (see project vs module in IntelliJ)
  5. That's it for configuring. Click "Apply", and close the window. Here's an example final result:

enter image description here

  • Note that my Main class is part of a package named Demo, but having a package is not necessary.
  1. Inside the main class, make sure there's a main method.
    See @Josiah Yoder answer for java, and for Scala it's:

    def main(args: Array[String]): Unit = {
    }
    
  2. That's it. You should now have the green run and debug buttons enabled.

Solution 24 - Intellij Idea

Seems there are version conflicts between plugins and IDEA itself that commonly break this functionality. Many of the solution here indicate people manually trying to identify the plug in, I found that to be impossible. So here is a generic way, without having to uninstall IDEA as one solution proposed:

File > Settings > Plugins > gear icon > disable all downloaded plugins

This fixed it for me.

Solution 25 - Intellij Idea

Search for pom.xml file --> Right Click on pom.xml --> Click on Add as Maven Project.

You should get a pop-up, saying downloading Mavin Plugin.

enter image description here

Wait till it gets completed. It takes some time depending on the number of content in pom.xml.

In the below screenshot, "BackendApp.java" is Driver Java file that contains

> public static void main(String[] args){}

Right Click on such driver java file and you see Run option in green color.

enter image description here

Solution 26 - Intellij Idea

Make sure the method is not static! JUnit only allows @Test before instance methods but Intellij doesn't complain even if you use @Test above a static method.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKannan EkanathView Question on Stackoverflow
Solution 1 - Intellij IdeaGuchelkabenView Answer on Stackoverflow
Solution 2 - Intellij IdeaGreenGiantView Answer on Stackoverflow
Solution 3 - Intellij IdeaJosiah YoderView Answer on Stackoverflow
Solution 4 - Intellij Ideauser5779136View Answer on Stackoverflow
Solution 5 - Intellij IdeaTomView Answer on Stackoverflow
Solution 6 - Intellij IdeaKannan EkanathView Answer on Stackoverflow
Solution 7 - Intellij IdeaPleymorView Answer on Stackoverflow
Solution 8 - Intellij IdeaEtchView Answer on Stackoverflow
Solution 9 - Intellij IdeaStephen AndersonView Answer on Stackoverflow
Solution 10 - Intellij IdeaniranjanView Answer on Stackoverflow
Solution 11 - Intellij IdeaboucekvView Answer on Stackoverflow
Solution 12 - Intellij IdeaDanView Answer on Stackoverflow
Solution 13 - Intellij IdeaThommView Answer on Stackoverflow
Solution 14 - Intellij Ideagouri pandaView Answer on Stackoverflow
Solution 15 - Intellij IdeaGuy SadounView Answer on Stackoverflow
Solution 16 - Intellij IdeaChandrahasanView Answer on Stackoverflow
Solution 17 - Intellij IdeaJFRANCKView Answer on Stackoverflow
Solution 18 - Intellij IdeaLineView Answer on Stackoverflow
Solution 19 - Intellij Ideaphil_20686View Answer on Stackoverflow
Solution 20 - Intellij IdeaNaresh KumarView Answer on Stackoverflow
Solution 21 - Intellij IdeaTaninoView Answer on Stackoverflow
Solution 22 - Intellij IdeaT04435View Answer on Stackoverflow
Solution 23 - Intellij IdeaOfirDView Answer on Stackoverflow
Solution 24 - Intellij IdeagunslingorView Answer on Stackoverflow
Solution 25 - Intellij IdeaAjayView Answer on Stackoverflow
Solution 26 - Intellij IdeaGoldCredentialView Answer on Stackoverflow