JUnit Interview Question
A list of top frequently asked JUnit interview questions and answers are given below.
1) What is Testing?
Testing is the process of checking the functionality of the application whether it fulfills the requirement or not.
2) What is JUnit?
JUnit is the testing framework, it is used for unit testing of Java code.
3) What is unit testing?
The process of testing individual functionality (known as a unit) of the application is called unit testing.
4) What is the difference between manual testing and automated testing?
Manual testing is performed by Human, so it is time-consuming and costly. Automated testing is performed by testing tools or programs, so it is fast and less costly.
5) Give some disadvantages of manual testing.
Following are some disadvantages of manual testing:
- The testing is very time consuming and is very tiring.
- The testing demands a very big investment in the human resources.
- The testing is less reliable
- The testing cannot be programmed.
6) List out some advantages of automated testing.
Some of the advantages of automated testing are:
- It is very fast.
- Investment is very less.
- Testing is more reliable.
- The testing can be programmed.
7) Is it necessary to write the test case for every logic?
No, we should write the test case only for that logic that can be reasonably broken.
8) What are the useful JUnit extensions?
- JWebUnit
- XMLUnit
- Cactus
- MockObject
9) What are the features of JUnit?
- Opensource
- Annotation support for test cases
- Assertion support for checking the expected result
- Test runner support to execute the test case
10) How is the testing of the ‘protected’ method done?
To test the protected method, the test class is declared in the same package as the target class.
11) How is the testing of ‘private’ method done?
There is no direct way for testing of the private method; hence manual testing is to be performed, or the method is changed to “protected” method.
12) If the JUnit method’s return type is ‘string’, what will happen?
JUnit test methods are designed to return ‘void’. So the execution will fail.
13) Is the use of ‘main’ method possible for unit testing?
Yes
14) Is it necessary to write the test class to test every class?
No
15) What does XMLUnit provide?
Junit extension class, XMLTestCase and set of supporting classes is provided by the XMLUnit.
16) List the core components of Cactus.
- Cactus Framework
- Cactus Integration Module
17) What are the methods in fixtures?
- setup
- tearDown
18) What is the Unit Test Case?
A Unit Test Case is the combination of input data and expected output result. It is defined to test the functionality of a unit.
19) What is the use of @Test annotation?
The @Test annotation is used to mark the method as the test method.
20) What is the test suit?
The test suit allows us to group multiple test cases so that it can be run together. TestSuit is the container class under junit.framework.TestSuite package.
21) What does test runner?
The test runner is used to execute the test cases.
22) What are the important JUnit annotations?
The test runner is used to execute the test cases.
- @Test
- @BeforeClass
- @Before
- @After
- @AfterClass
23) What does Assert class?
Assert class provides methods to test the test cases.