how can I add junit.jar in intellij?
Solution 1
You have installed JUnit plugin for IntelliJ IDEA, that means that IDE recognizes and support JUnit tests.
However, you are missing JUnit dependency on your classpath. That mean add proper JAR file to the classpath or if you are using dependency management tool such as maven, add it to your dependencies section.
Alternative 1 - Maven dependency - put this in you pom.xml file under <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
Alternative 2 - Gradle dependency - put this in your build.gradle file
apply plugin: 'java'
dependencies {
testCompile 'junit:junit:4.12'
}
Alternative 3 - Download the JARs and put it on your classpath.
Download the following JARs and put them on your classpath:
Solution 2
From the main menu, select File->Project Structure-> Libraries
and click '+' & select from maven
after when open the dialog prompt
type org.junit.jupiter:junit-jupiter:5.4.2
in the dialog prompt
ex-:
now, click 'ok' & run again
Solution 3
It's also worth double checking your configuration to make sure your test run config is pointing at the test portion of your project, not the entire project.
Related videos on Youtube
Qasem
I'm now a Computational neuroscience research assistant at DML in CE department at Sharif University of technology. I studied my Bachelor of Science in Software engineering in the CE department at Sharif University of technology. I was at Helli high school studying Physics and Math and then I studied Astrophysics Olympiad. I worked in the company Pushe as a software engineer and public relations. Before that, I was an intern in a software security company for months. I like to travel and meet people and I love Persian literature.
Updated on July 09, 2022Comments
-
Qasem almost 2 years
when I write
import org.junit.*
the IDE says can not resolve symbol junit and show it in red color. then I can't even import unit test; niether junit nor groovy Junit.and I thought maybe I should first install the junit.jar, but junit already has been installed in plugins! how can I install junit.jar? if it's necessary
it's not how to add jUnit to my program but how to add that plugin (maybe) that question is here configuring intellij ...
the IDE is intellij community edition and my OS is linux.
-
vikingsteve almost 8 yearsPossible duplicate of Configuring IntelliJ IDEA for unit testing with JUnit
-
-
chrips almost 6 yearsI have JUnit installed IntelliJ but somehow junit is red for me... except its not a Maven or Gradle project so no pom.xml. Any ideas? On Windows I was able to just Create a test right off the bat!
-
Vojtech Ruzicka almost 6 yearsYou can add library manually under File->Project Structure->Libraries
-
Qasem over 4 yearsI do this, more often now. It works properly, I suppose!
-
user8400852 over 2 yearsThanks, that was it for me.