Run a single Junit Test in IntelliJ IDEA
Asked Answered
D

5

8

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

enter image description here

Deepsix answered 1/7, 2019 at 18:36 Comment(2)
If you look at your code, you should see a little green arrow to the left of the methodKumler
Or you can right click the method name and select run myMethodName().Keil
P
9

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.

Playmate answered 1/7, 2019 at 18:47 Comment(2)
could you please tell me how to debug a particular junit test in Intellij. Earlier i used eclipse but I am unable to do so in intelijBeach
You select the method, either in the editor or the structure view, right click and select "debug". Also note that intellij has excellent help pages explaining such things.Playmate
D
3

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!

enter image description here

Diluvial answered 21/5, 2023 at 6:32 Comment(0)
H
1

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.

Heel answered 1/7, 2019 at 20:31 Comment(2)
Sadly, this is broken in IntelliJ 2019.3.3 (at least for Kotlin). Until you run all the tests in the test suite, you cannot run an individual test.Chalk
Agree with John Kaster. You cannot run an individual test whether it is Java or Kotlin.Dickman
T
0

Please place caret inside test method you want to launch and using right click context menu launch single test.

Tempe answered 1/7, 2019 at 18:38 Comment(0)
B
0

You should see all your tests annotated with a small red-green symbol, as in this view:

small red-green IJ symbol

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.

Beaux answered 26/7, 2024 at 22:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.