You need to add junit
library to the classpath of your project. There are several choices to achieve it depending on your development setup.
Command line: In the case of command line invocations, you will have to add junit.jar
to the classpath of your application with java -cp /path/to/junit.jar
. Take a look at the answers here.
Using eclipse: Eclipse distributions are bundled with this library and this is how you can use it for your project. Right click on the eclipse project and navigate:
Properties -> Java Build Path -> Libraries -> Add Library -> JUnit -> Junit 3/4
In the scenarios where you want to use a different version of the jar, instead of clicking on Add Library above you should click on Add External Jar and locate the library on the file system.
Right-click on the eclipse project and navigate:
Properties -> Java Build Path -> Libraries -> Add Library -> JUnit -> Junit 3/4
It works on mine.
If you use maven and this piece of code is located in the main
folder, try relocating it to the test
folder.
you can easily search for a line like "@Test" and then use the quickfix "add junit 4 library to the build path" at this line. i think this is faster than adding junit manually to the project.
If you are using eclipse and working on a maven project, then also the above steps work.
Right-click on your root folder.
Properties -> Java Build Path -> Libraries -> Add Library -> JUnit -> Junit 3/4
Step By Step Instructions here
you need to add Junit dependency in pom.xml file, it means you need to update with latest version.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
Seem to Junit jar file is not in path also make sure you are using jdk1.5 or above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With