Junit Testing Framework

Junit Testing Framework

  1. Is use to write a test case for the code.
  2. These test cases have to provide by developer.
  3. Unite testing the way by which you can test the smallest functionality of the code.
  4. Junit Framework will provide a way to right unit test cases and also it will generate the report which will use to a analysis purpose.
  5. You can identify the code coverage of your code by executing unit test cases.
  6. Junit testing is the case of unit test cases, you can also use mocking framework like Mockito in unite test cases.
  7. To Implement unit testing into your application you have to add jar file of Junit framework.



Steps to create test source folder

  1. Right click on project
  2. Got “New” -> “Source Folder”
  3. Give name to a folder as “test”
  4. Click on create button


Create Junit Test class

  1. Right Click on test source folder.
  2. Got “New” and Select “Junit Test Case”
  3. Give name to a test class. (Naming Convention for Test class is, test class name should be a classname followed with “Test” word)
  4. Select The Junit version, and then Click on finish


Code coverage plugin

  1. Got to “Help” menu -> select “Eclipse Marketpalce”
  2. Search for “code coverage” and install following plugin


  1. Add “sonarlint” plugin for code review.



Unit Test Case Annotation


  • This is use to perform initialization activity before execution of any test case.
  • This method gets executes only once and before all unit test cases and even before constructor class.
  • This method has to declare as static.



  • This method is use to perform closing activities after execution of all the test case.
  • This method gets executes only once and after all the method execution.
  • This method has to declare as static



  • This method executes before each test case.
  • This method is mostly use to initialize any data for test case execution.



  • This method executes after each test case.
  • This method is mostly use to perform closing activity for test case execution.



  • This annotation is use to define any class as a unit test case

Here, you can call your actual/logic and compare the out pout with expected output using assertion.


Join Telegram : Click Here


All Full Stack Java Study Material


Java the programing language


Job’s For Fresher


Share This Information To Your Friends and Your College Group’s, To Help Them !