Running JUnit 4 Tests in IntelliJ IDEA 5.1

Note: The tip was originally posted at t800t8.blogspot.com 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:


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:
This entry was posted in Tips & Tricks. Bookmark the permalink.

3 Responses to Running JUnit 4 Tests in IntelliJ IDEA 5.1

  1. nils says:

    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:

    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 http://www.intellij.net/eap.

  3. Mitch says:

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

Leave a Reply

Your email address will not be published. Required fields are marked *