I am new in IntelliJ IDEA and I want to execute a single Junit test as I do in Eclipse but I haven't seen this option
IntelliJ runs the unit test in context of your selection!
When you place the cursor on the class name, it will run the whole class. If you select a method name, only that method gets executed (upon turning to the menu or context menu).
You can also select a package in the project view and get to corresponding behavior.
I fixed my issue by Uncheck the "Delegate IDE build/run actions to Maven". I think this works for IntelliJ version higher( in my case is 2023.1.1) Go to Settings -> Build, Execution, Deployment -> Maven -> Runner and Uncheck the "Delegate IDE build/run actions to Maven".
Hope it is useful!
Open the class where the tests are located and check the part where inteliJ shows the the number of lines, at the beginning of each test method there is a green icon (looks like a play button) just hit that icon and the specific test method will be executed.
Please place caret inside test method you want to launch and using right click context menu launch single test.
You should see all your tests annotated with a small red-green symbol, as in this view:
If not, ensure that the folder that contains your .java files is selected as a "Source Root" folder (right-click on folder, Mark Folder As...). It will be blue. Also, be sure that if it's a Maven or Gradle project, you check that the dependencies in the Maven/Gradle window are as you expect them to be (these ultimately form the classpath against which your unit tests will be run).
If successful, you should then be able to right-click your test and see "Run..." and "Debug..." options, or use the cryptic IJ key sequence of your choice to run.
© 2022 - 2025 — McMap. All rights reserved.
run myMethodName()
. – Keil