Junit Testing Framework
- Is use to write a test case for the code.
- These test cases have to provide by developer.
- Unite testing the way by which you can test the smallest functionality of the code.
- 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.
- You can identify the code coverage of your code by executing unit test cases.
- Junit testing is the case of unit test cases, you can also use mocking framework like Mockito in unite test cases.
- To Implement unit testing into your application you have to add jar file of Junit framework.
Steps to create test source folder
- Right click on project
- Got “New” -> “Source Folder”
- Give name to a folder as “test”
- Click on create button
Create Junit Test class
- Right Click on test source folder.
- Got “New” and Select “Junit Test Case”
- Give name to a test class. (Naming Convention for Test class is, test class name should be a classname followed with “Test” word)
- Select The Junit version, and then Click on finish
Code coverage plugin
- Got to “Help” menu -> select “Eclipse Marketpalce”
- Search for “code coverage” and install following plugin
- 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