Running JUnit 4 Tests in IntelliJ IDEA 5.1


Note: The tip was originally posted at by t800t8

Although the full JUnit 4 support will be added only in IntelliJ IDEA 6.0, you can run JUnit 4 tests right now, in the 5.1 release. Just follow the instructions below.

Note: Of course, you need to add the JUnit 4 JAR file to the classpath first.

1.   Click Settings | File Templates.
2.   In the Templates tab, create new template and name it “JUnit 4 Test Class” or anything you like.
3.   Paste the following code fragment into the text box:

package ${PACKAGE_NAME};

   import org.junit.*;
   import junit.framework.JUnit4TestAdapter;

   public class ${Name} {
       public static junit.framework.Test suite() {
           return new JUnit4TestAdapter(${Name}.class);
       public void setUp() {           

       public void tearDown() {          

       public void testSomething() {           

You can see the results on the screenshot.

After you apply the chages, use this template to create JUnit 4 test classes. To run the tests, simply click Run.
Enjoy it and happy unit testing!

Technorati tags:
Comments below can no longer be edited.

3 Responses to Running JUnit 4 Tests in IntelliJ IDEA 5.1

  1. nils says:

    April 7, 2006

    I’ve tried this and it works…kind of. The problem I had was that if I run all (working) tests in a package, I get the green bar but each JUnit 4 test class will be colored yellow in the run window. Another problem is that the run window does not show the test method names, but “n test case(s)” instad.

  2. Alexandra Rusina says:

    April 7, 2006

    Well, it’s a kind of work-around. JUnit4 will be supported in IntelliJ IDEA 6.0 Release. You can try this functionality in the new EAP build (5218) at

  3. Mitch says:

    August 15, 2007

    This only works because of the junit 3 syntax that is being used. From what I can tell it’s completely ignoring the annotations.


Subscribe for updates