Reputation: 17631
In IntelliJ when I right click on a test I dont see a "Run ClassX or MethodY" anymore. In fact 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
This happens for all projects.
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 don't get Run option on right click:
Upvotes: 68
Views: 141347
Reputation: 2208
I had this problem with a Kotlin project. Following action solved it:
test
folder -> select Mark Directory as
-> choose Test Sources Root
Upvotes: 7
Reputation: 3776
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) {
}
Every keyword in the above statement is critical. If you omit one, IntelliJ wont' recognize it. Easy-to-forget keywords are static, void, and the String[] args argument.
I had forgotten the arguments in mine ;-)
Also make sure your source code is inside a src
folder which is marked as such by IntelliJ.
Upvotes: 31
Reputation: 1651
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
Upvotes: 3
Reputation:
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.
Upvotes: 0
Reputation: 207
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.
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.
Upvotes: 1
Reputation: 1486
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.
Upvotes: 0
Reputation: 10510
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:
Now, let's go through the required fields:
Main
class is part of a package named Demo
, but having a package is not necessary.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 = {
}
That's it. You should now have the green run and debug buttons enabled.
Upvotes: 0
Reputation: 1230
I had the same problem. I solve it by
File -> Invalidate Caches / Restart
right click on the top pom.xml -> Maven -> reimport
Upvotes: 4
Reputation: 364
Unfortunately, none of these worked for me. I had to
Upvotes: 1
Reputation: 1285
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)
Upvotes: 57
Reputation: 14032
In my case, my project is using Bazel.
The solution was to sync Bazel from Bazel plugin.
Upvotes: 0
Reputation: 2079
I could resolve the issue by disabling the Gradle plugin from the Plugin menu and restart.
Upvotes: 3
Reputation: 535
in my case, I did not have an output folder. file -> project structure -> under 'project' tab there's 'Project compiler output' -> define your folder.
Upvotes: 1
Reputation: 184
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.
Upvotes: 0
Reputation: 311
In my case i right clicked the src folder and went to -> mark directory as -> sources root.
Upvotes: 10
Reputation: 322
if you can see the play button in left side of the main function then click right click and press run.
Upvotes: 1
Reputation: 516
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
Upvotes: 1
Reputation: 4093
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.
Upvotes: 20
Reputation: 2921
Disabling gradle
plugin solved the issue for me (community edition 2018.2)
Upvotes: 7
Reputation: 9801
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.
Upvotes: 1
Reputation: 1
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
Upvotes: 0
Reputation: 4080
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.
Upvotes: 0
Reputation: 5266
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() {
Upvotes: 65
Reputation: 159
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.
Upvotes: 2
Reputation:
In my case, the cause was disabled JUnit plugin. (File — Settings — Plugins — JUnit, check, OK)
Upvotes: 26
Reputation: 390
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...
Upvotes: 2
Reputation: 17631
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....
Upvotes: 9