Tech and Media Labs
This site uses cookies to improve the user experience.




Running Unit Tests Inside IntelliJ IDEA

Jakob Jenkov
Last update: 2014-05-24

If you are using IntelliJ IDEA as Java IDE, as I am (my favourite Java IDE :-) ), then you can run all your unit tests from inside IntelliJ IDEA. In this text I will show you how. If you click the screenshots, they open in a larger format, in a new window.

Create a Run Configuration

First you need to create a "Run Configuration". You do that by opening the "Run" menu, and selecting "Edit Configuration". Here is a screenshot of that:

Opening the Edit Configurations in the Run menu in IntelliJ IDEA
Opening the Run menu, and selecting the Edit Configurations item.

The Edit Configurations dialog looks like this:

To add a new Run Configuration, click the + button. A drop down list appears. Select a new Junit configuration. Here is how it looks:

Adding a new JUnit Run Configuration
Adding a new JUnit Run Configuration.

Enter information into the JUnit configuration form. I've selected the radio button "All in package". This means that IDEA will run all tests in a certain Java package, and all subpackages recursively. In this example I have chosen a top level package, com.jenkov. I have named the configuration "All Tests". Then I click the "OK" button.

Enter data into the JUnit configuration form
Enter data into the JUnit configuration form.

After the new JUnit Run Configuration has been added, it appears in the "Run" drop down box in the toolbar. Here is a screenshot of how that looks:

The Run Configuration is available in the Run drop down.
The Run Configuration is available in the Run drop down.

Running the Tests

You can now run all unit tests in package "com.jenkov" by clicking the green "Run" button, next to the Run drop down box. If you do so, you get the following result window:

The JUnit test result window.
The JUnit test result window.

Jakob Jenkov




Copyright  Jenkov Aps
Close TOC