IntelliJ reporting "No junit.jar" when running tests after upgrading 2019.2

已回答

My snap Linux installation of IntelliJ updated today to 2019.2 and since then now when I open my project and try to run JUnit tests I'm getting the error "No junit.jar" .

The tests were running fine previously before the version updated.

Does anyone know what the fix is for this?

0

What's the path to junit.jar in your project configuration? You may need to update it or switch to the Maven dependency. Using junit.jar from IntelliJ IDEA distribution might not be the best option.

0
Avatar
Permanently deleted user

I'm having the same issue on MacOS with a maven project.
I am able to run the maven tests from the command line (`mvn surefire:test`), but when trying to run the test from IntelliJ, I get this in the Event Log:

10:13 AM All files are up-to-date

10:13 AM Error running 'All in [project-name]': No junit.jar

0

Try to delete .idea directory and reimport the project from pom.xml.

3
Avatar
Permanently deleted user

I have a similar problem with 

IntelliJ IDEA 2019.2.2 (Ultimate Edition)
Build #IU-192.6603.28, built on September 6, 2019

The project was originally a JUnit 4 project then was converted to JUnit 5 - with no JUnit 4 libs in the poms and no "vintage" support in the poms.  After modifying poms to only use JUnit5 I also tried deleted the .idea directory and reimported the project from pom.xml.  Still didn't fix the issue.  

Note that this project is a multi-module pom with both modules and a parent pom.  The "root" pom.xml however doesn't have any junit or jupiter dependencies.  When I right-click on the root project and select Run 'All Tests' I also get the "No junit.jar" issue.

I have a similar issue opened here:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006399760-IDEA-2019-2-2-Ultimate-Edition-requires-junit-vintage-engine-for-Maven-package-using-only-JUnit5

No work-around's I've tried so far get me past this issue.  I'd also like to mention that it's often not possible to have IntelliJ download the jar from the Maven website even with a proxy since some firms block that and only allow internal Maven repos, which also have only certain versions of libs (i.e. maven-surefire-plugin:2.22.0 is found but not maven-surefire-plugin:2.22.2 is not found).  So the work-arounds others have noted for some similar issues where you change proxy settings perhaps since IntelliJ is trying to grab a jar from somewhere, won't work for us.  This was the link where that was noted: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360002590379-IntelliJ-IDEA-repeatedly-resolving-junit-platform-launcher

Perhaps it's best if IntelliJ bundles a specific Junit.jar/junit5.jar and if it sees that Maven has a different version it uses it?

2

What is the full command line with the error?

Can you run Junit tests from command line Maven?

0
Avatar
Permanently deleted user

Andrey - can you walk me thru how I can get the full command line with the error?  I'm right-clicking on the root project and select Run 'All Tests' .  I don't see command-line in the Event Log.  The "No junit.jar" shows in the bottom-left of the screen.

As for whether these run properly from the command line Maven, yes they do via "mvn clean verify".

0

>how I can get the full command line with the error?

This is the very first line in the run tool window.

 

Have you tried running tests by Maven from command line?

0
Avatar
Permanently deleted user

> how I can get the full command line with the error?

This is the very first line in the run tool window.

The problem is that it never gets that far.  See picture above.  No tests are run, and there is nothing in the "Test Results" of the Run tool window.

As for running via Maven command line, as noted in reply above I have run them, and they run ok via Maven (via "mvn clean verify").

This is what is in my Project Structure related to JUnit (I have not seen a way to add "Junit 5.2 to the classpath" in this version of IntelliJ as noted on some other Jet Brains links when JUnit 5 support was first added to the product) :

 

0

>This is what is in my Project Structure related to JUnit (I have not seen a way to add "Junit 5.2 to the classpath" in this version of IntelliJ as noted on some other Jet Brains links when JUnit 5 support was first added to the product) :

You need to make sure the necessary Junit5 dependencies are added into Maven pom.xml file. Check e.g. https://www.mkyong.com/junit5/junit-5-maven-examples/

If issue remains, provide a sample project.

0
Avatar
Permanently deleted user

I've experienced the same problem. The issue seems to be related (at least for me) to how IntelliJ Gradle plugin changed its operation. My IntelliJ projects used to have only one module per Gradle file because I was always clearing "Create separate module per source set". With recent changes, Gradle plugin generates sub-modules per source set and you have no control over it anymore (it seems). So now I have "foo-bar" module with two submodules "main" and "test". My IntelliJ project had a bunch of run configurations for running my junit tests. Running any of these produced "No junit.jar" error with the latest IntelliJ versions. I had to change "Use classpath of module" setting in the run configurations to point to "foo-bar.test" instead of the old value "foo-bar".

3

With the new mechanism of creating separate module per source set we provide more accurate composition of compile/run classpaths for different source sets. It makes the IDE configuration match the Gradle configurations more closer and we intend to make it work in most possible usecases.

0
Avatar
Permanently deleted user

This happened for me too. 

Solution:- just enable the junit plugin in eclipse if disabled else (disable it and enable it again) and unckeck the argline checkbox in intelij plugin preferences and there you go works fine.

thank me later.

1

Solution : -Add dependency for junit in project structure.

Steps: - 

Go to IntelliJ project.

Select File->Project Structure

Under project Settings -> Modules ->Dependencies.

Click + button and add a dependency to junit-4.12.jar and another one hemcrest-core-1.3.jar from IntelliJ installed location. This is path for jar in mac for me , 

Select apply and then after tests started working for me.

HTH, thanks!

 

 

1

Sumitpkedia We don't recommend depending on the IDE installation files, either use Maven/Gradle dependency or copy the jars to your project and add a project library that can be shared with other users with the project if needed.

0

@Serge Baranov

So what is the solution? I am having this problem as well. We run multi-module projects with the parent/root project having no code and thus no tests. It is bad practice to declare a dependency where it is not needed or used. The projects run just fine from the terminal and in our CI/CD build and it worked just fine in the past.

My projects have a library to junit defined automatically and still fail.

What better solution do you have to resolve this issue?

0

Will Schneider

Please contact support at https://intellij-support.jetbrains.com/hc/requests/new with the sample project to reproduce attached. It's a different issue.

0

I've the same problem as stated by Anthony J Falabella and yes, mvn test works normally. The typical "whole project" option in IntelliJ coverage doesn't work using maven with submodules when parent pom.xml doesn't have any dependencies for junit. My submodules did.

The question is if there is no test neither source folder (in parent maven module), why did IntelliJ carry about JUnit?

It seems IntelliJ doesn't understood the submodules configuration properly and check JUnit dependency first of all.

Andrey Dernov ask if did mvn test work in parent module, yes it did!

3

I had the same error message when running with coverage ("Error running 'Test Coverage': No junit.jar").

Resolved the issue in the run configuration:

1. Under "Build and Run" selecting "All in package" : com.my.project
2. Under "Code Coverage" adding com.my.project

0

Hello from 2025, I have the same problem with a multi-module gradle project.

Running ./gradlew works

Running with Idea works only for a single module, if I go into it's directory and right-click on /src/test directory.

0
Could you confirm in your JUnit run configuration settings, the value of the "Search for test" option is set to "In whole project" ?
0

There's nothing like “In whole project”. There is “in directory”, but after setting it to project root, it it still showed the same error.

0

It should be under "Modify options". 
Run configuration => Modify options => Search for tests => and select In whole project

 

0

Thanks, the “no junit.jar” error went away, but now I get “Test Framework quit unexpectedly”

For the record, running tests by right click on gradle goal works:

And clicking on “src/test” in a a module works.

 

0
Please create a support request at https://intellij-support.jetbrains.com/hc/en-us/requests/new so we could check the issue in detail.
0

请先登录再写评论。