Skip to main content

Junit - Annotations

Junit is Unit Testing Framework which is open source tools and basically it is used for java developers .So if you are not clear about what is Unit Testing , then first you have to go through what is unit testing.
In these blog you will be having idea about what are the annotations and how to use it.
In Junit the program are executed by Annotations
These are the below annotations:
  1. @BeforeClass
  2. @Before
  3. @Test
  4. @After
  5. @AfterClass
To Support the Java Project with Junit you need to have 2 libraries
  • hamcrest
  • junit
Download this library from here Junit 


Click on Download and install







Click on both jar file 
and download the latest jar 
Go to Eclipse and Create a Java Project  

File->New->Java Project (if you dont see the java project go to other and then Select Java projects

Write down the Project name as Junitexample in Project name

Right Click on the project go to -> Build Path -> Configure Build Path ( click on this)



1.Click on Libraries Tab
2. Click on Add External Jar

3. Click on location at which place you have  kept your jar files
4.Select both the jar file
Your library should be shown here.

Create a new Java Class 
File ->New -> Class

Give the name to the class FirstJunitExample

Then write down these code


Now Run the Junit Program as Junit Test


These show result of Junit Program.
It shows the green color means it successfully exceuted the test cases.





Thanks for reading the blog if you like please share it 




Comments