In this blogpost, we will focus on how to configure and setup JUnit with Eclipse IDE, and execute a simple JUnit test case.
Step 1 : Downloading JUnit jar file
Go to http://www.java2s.com/Code/Jar/j/Downloadjunitjar.htm and download junit.jar.zip file.
Step 2 : Create a Java project in Eclipse
Open Eclipse IDE.
Go to File -> New -> Java Project, and finish the process by giving project name and selecting JRE version .
For more information on this, visit this link.
Step 3 : Add JUnit jar to build path of the project
Once after creating a Java project, we need to add the JUnit.jar file downloaded in first step to the build path of the project.
Step 4 : Creating first JUnit test case
Now, since the initial setup is done, it’s time to create our first JUnit test case.
Follow the below steps :
- Right click src folder of project
- Go to New, and select JUnit Test case
- Give name to test case, and package if you want, and click on Finish.
- You will be able to see the test case class created, with default @Test annotation.
Step 5 : Executing the JUnit test case
In order to execute the JUnit test case, just right click on test case class file -> Run As -> JUnit Test.
Or if the test case class is opened, we can right click anywhere in the class file, and select JUnit Test from Run as option.
That is all from this blogpost, hope it helps you!!