Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure IntelliJ for running test with JUnit 4?

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 ?

like image 597
fabien7474 Avatar asked May 08 '10 14:05

fabien7474


People also ask

How do I change JUnit 4 to JUnit 5 in IntelliJ?

Press ⌥⏎, or Alt+Enter, in the class name and IntelliJ IDEA offers to migrate the test class to JUnit 5. The refactoring preview window will show the places where changes will be made, in this case a number of annotations will be changed to the new JUnit 5 annotations.

How do I enable testing in IntelliJ?

Add a new test In your production code in the editor, place the caret at the class for which you want to create a test, press Alt+Enter , and select Create Test. In the Create Test dialog, select the library that you want to use. If you don't have the necessary library yet, you will be prompted to download it.


3 Answers

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 !

like image 153
fabien7474 Avatar answered Oct 24 '22 05:10

fabien7474


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

@RunWith(JUnit4.class) MyTestClass {} 
like image 31
Jaime Hablutzel Avatar answered Oct 24 '22 04:10

Jaime Hablutzel


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!

like image 29
Chris Murphy Avatar answered Oct 24 '22 04:10

Chris Murphy