How to configure IntelliJ for running test with JUnit 4?

21,786

Solution 1

I found it!

  1. Go to Run/Debug Configurations
  2. Add new configuration and choose a JUnit
  3. In the configuration tab, add "-junit4" to the Test run parameters input field

And that's done !

Solution 2

You can annotate your test class with an annotation to indicate junit the runner it will use

@RunWith(JUnit4.class) MyTestClass {} 

Solution 3

I tried to put:

@RunWith(JUnit4.class) 

at the beginning of a test. IntelliJ complained about this, but asked to 'load' JUnit4.class. So I deleted @RunWith(JUnit4.class). But the 'loading' seems to have fixed the problem - @Ignore is now respected!

Share:
21,786
Kapil Gund
Author by

Kapil Gund

My mojo is Quality is Free & I believe in xDD : DDD, BDD, TDD and Clean Code.

Updated on March 08, 2020

Comments

  • Kapil Gund
    Kapil Gund over 4 years

    Should be simple but I couldn't figure it out.

    When running my unit test inside IntelliJ, I could not find a way to tell IntelliJ-9.0 that it should use JUnit4 instead of JUnit3.

    When a test fails, IntelliJ console displays:

    MyTests.testConstraints(MyTests.groovy:20) at

    ...

    com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:108) at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:42) ...

    Do you know how to replace JUnit3 by JUnit4 ?