Getting started with JUnit

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.

download-junit-jar-file.PNG

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.

adding-junit-jar-file

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

create-junit-test-case-in-eclipse.png

  • Give name to test case, and package if you want, and click on Finish.

create-junit-test-case-in-eclipse2

  • You will be able to see the test case class created, with default @Test annotation.

create-junit-test-case-in-eclipse3

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.

executing-junit-test-case.png

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.

execution-of-junit-test-case.PNG

That is all from this blogpost, hope it helps you!!

Cheers 🙂

Advertisements

#download-junit, #getting-started-with-junit, #installation-of-junit, #junit