Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Practice InterviewNew Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

JUnit Interview Questions and Answers

Ques 1. What is JUnit?

Ans. JUnit is a software testing framework for unit testing, open Source Software maintained by the community. JUnit was originally written by Erich Gamma and Kent Beck.

► Test runners for running tests
► Test fixtures for sharing common test data
► Assertions for testing expected results

Is it helpful? Add Comment View Comments
Ques 2. Who Should Use JUnit?
Ans. JUnit is mostly used by developers for testing their written code. JUnit is designed for unit testing, which is really a coding process, not a testing process. But many testers or QA engineers, are also required to use JUnit for unit testing.
Is it helpful? Add Comment View Comments
Ques 3. Why Do You Use JUnit to Test Your Code?
Ans. ► Using JUnit makes unit testing easier and faster.
► Writing more tests will make more productive, not less productive.
► Unit Tests should be done as soon as possible at the code unit level so at that point we capture the issue and fix it.
Is it helpful? Add Comment View Comments
Ques 4. How To Compile a JUnit Test Class?
Ans. As JUnit code is written in java, compiling a JUnit test class is like compiling any other Java classes. The only thing you need watch out is that the JUnit JAR file must be included in the classpath like junit.jar etc. For example, to compile the test class described previously, you should do this:

javac -cp junit-4.4.jar

and it will create .class file.

The compilation is ok, if you see the LoginTest.class file.
Is it helpful? Add Comment View Comments
Ques 5. How To Write a Simple JUnit Test Class?
Ans. You should be able to write this simple test class with one test method:

import org.junit.*;

public class LoginTest


@Test public void testLogin()


String username = \\\"withoutbook\\\";

Assert.assertEquals(\\\"withoutbook\\\", username);



Here first argument in assertEquals is the known parameter which should be equal to username. If both are same it will send me true and if both are not equal sends me false.
Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2020 WithoutBook