Junit - Interview Questions and Answers

Q1. What is Junit ?

Ans Its an Open Source Java framework for Automated Unit Testing. 

Q2. Is Junit used for Manual Testing or Automated Testing ?

Ans. Automated Testing.

Q1.  Difference between Assert and Verify ?

Ans. Assert works only if assertions ( -ea ) are enabled which is not required for Verify.

Assert throws an exception and hence doesn't continue with the test if assert evaluates to false whereas it's not so with Verify.

Q2.  What are the annotations used in Junit  with Junit4 ?

Ans. @Test

The Test annotation indicates that the public void method to which it is attached can be run as a test case.


The Before annotation indicates that this method must be executed before each test in the class, so as to execute some preconditions necessary for the test.


The BeforeClass annotation indicates that the static method to which is attached must be executed once and before all tests in the class.


The After annotation indicates that this method gets executed after execution of each test.


The AfterClass annotation can be used when a method needs to be executed after executing all the tests in a JUnit Test Case class so as to clean-up the set-up. 


The Ignore annotation can be used when you want temporarily disable the execution of a specific test.