Showing posts with label JUnit settings. Show all posts
Showing posts with label JUnit settings. Show all posts

Tuesday, 23 June 2015

Eclipse: Env Setup and Creating and Running a JUnit Test case.

Below are the steps to create and Run a JUnit Test case form the Eclipse

1.    Download the Junit jar from the location http://junit.org/ and also download the
     dependency jar hamcrest-core.jar.

2.    Create a new project in Eclipse. Right click on Project -> Properties -> Java Build Path -> Go to Libraries tab -> click on Add external Jars. Select the downloaded jars and add them.

3.     For creating a Junit test case, Right click on Project -> New -> Other -> Java -> Junit -> Select Junit Test Case.

a.     In the Next Window, Enter the name for the Junit Test Case and also select the Java class for which the test class is being created. Click on Next

b.     In the Next Window, Select the available methods for which the test method should be added and click on Finish.

4.    For running the test case, Right click on Project -> Run As -> JUnit Test. It should give the results accordingly.


If you are using Maven, Add the below dependency to pom.xml for JUnit. It will download the  JUnit and the hamcrest-core jars.

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
  <scope>test</scope>
</dependency>