Saturday, February 18, 2017

Junit Testing Interview Questions

In this article we will learn  Junit Framework Interview Questions and answers for Experienced Developers. Junit is an open-source testing framework for Java Programmers. The java programmer  can create test cases and test their own code. The current version is Junit 4. It is an important to development of test-driven development. This is the post for all experienced programming Developers.

1) What is Testing?

Ans:  Testing is the process of checking the functionality of the application whether it is working as per requirements. Software Testing is the process used to identify the correctness and quality of developed computer web applications. It helps to identify errors,gaps that means it check whether the actual results match the expected results.

2) What is Unit Testing?

Ans:  Unit Testing is the testing of single entitiy(class or method). It is very essential to every software company to give a quality product to their customers.

3) What is Junit?

Ans:  Junit is an open-source testing framework for Java Programmers. The java programmer  can create test cases and test their own code. It helps Programmers to accelerate programming speed and increase the quality of code.

4) What are the features of Junit?

Ans: The following are some of the important features of Junit:

  1. It is an open source framework any body can use free of cost and provides source code. It also provides Annotation to identify the test methods.
  2. It provides Assertions for testing expected results
  3. Junit tests can be run automatically and they check their own results and provide immediate feedback.
  4. It provides Test Runners for running tests.
  5. Junit Tests can be organized into test suites containing test cases and ever other test suites.
  6. Junit shows test progress in a bar that is green if test is going fine and it turns red when test fails.    
 5) How to install Junit?

Ans: To install Junit follow the  below steps:
  •   Download the latest version of Junit then referred to below as junit.zip
  •   Unzip the junit.zip distribution file to a directory referred to as %Junit_Home%
  •   Add Junit to the classpath?
  •   set CLASSPATH=%CLASSPATH%;%JUNIT_HOME%\junit.jar
  •   Test the installation by running the sample tests distributed with Junit. They simply type
  •  java.org.junit.runner.JUnitCore.org.junit.tests.AllTests
  • All the tests should pass with an "OK" message.
  • If the tests don't pass,verify that junit.jar is in the CLASSPATH
       
 6) What are the Core Features of JUnit?

Ans:  Junit Test Framework provides the following important features:
Test suites
Test Runners
Fixtures
Junit classes

7) How will you run Junit from command window?

Ans: To run Junit from command window follow the steps:

  • Set the CLASSPATH
  • invoke the runner
  • then type java.org.junit.runner.JunitCore
   
8) What is Manual Testing?

Ans: If Programmer executing the test cases manually without using any tool support is known as manual Testing.

9) What is Automated Testing?

Ans: If programmer taking the tool support and executing  the test cases by using automation tool is known as automation testing.

10) List out the disadvantage of Manual testing?

Ans: The following are the disadvantages of manual testing:

Time consuming and tedious: 

It takes long time to execute test cases because test cases are executed by human resources. So it is very slow and  and tedious

Investment in human resources:

 Every test case is executed by manually so more testers are required in manual testing.

Less Reliable:

Manual testing is less reliable as tests may not be performed with precision  each time because of human errors.    

11) What is Unit Test Case?

Ans: A Unit Test Case is a part of code which ensures that the another part of code(method) works as expected. To achieve those desired results quickly,test framework is required. Junit is perfect unit test framework for java programming language.



12)  What are Unit Tests written in Development Cycles?

Ans: Tests are written before the code during development in order to help coders write the best code.

13) Why not use System.out.print() for testing?

Ans: If use System.out.println() to debug the code will lead to manual scanning of the whole output every time the program is run to ensure the code is doing the expected operations. Moreover,in the long run,it takes lesser time to code Junit methods and test them on class files. 

14) Why does JUnit is only report the first failure in a single test?

Ans: JUnit is designed to work best with a number of small tests. Reporting multiple failures in a single test is generally a sign that the test does too much and it is big a unit test. It reports failure on each test. Since,it executes each test within a separate instance of the test cases.

15) Name the tools with which JUnit can be easily integrated?

Ans: JUnit Framework can be easily integrated with the following tools:

Eclipse
Ant
Maven

16) What is Fixture?

Ans: Fixture is a fixed state of a set of objects uses as a baseline for running tests.The main purpose of test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable. It includes the methods like setUp() which runs before every test invocation. tearDown() method which runs after every test method.

17) Define Test Suite?

Ans: Test Suite is a few unit test cases and run it together  That means it is bundle. In JUnit,both @RunWith and @Suite annotation are used to run the suite test.

18) What is Test Runner?

Ans: Test Runner is used for executing the test cases

19) What are Junit classes?

Ans:  Junit classes are used for writing and testing Junits. Some of the important classess are:

Assert:  It contains a set of assert methods
Test case: It contains a test case defines the fixture to run multiple tests
TestResult: It contains methods to collect the results of executing a test case
TestSuite: It is a composite of Tests.

20) How useful annotations in JUnit?

Ans: Annotations are like meta-tags that you can add to you code and apply them to methods or in class. The annotations are useful in JUnit gives us information about test methods,which methods are going to run before & after test methods,which methods run before & after all the methods,which methods or class will be ignore during execution

21) What is the purpose of org.junit.TestSuite class?

Ans:  A TestSuite is a Compoiste of Tests. It runs a collection of test cases. 

22) What is the purpose of @Test annotation in JUnit?

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

23)  What is the use of  @Before annotation in JUnit?

Ans:  Several tests need similar objects created before they can run. Annotating a public void method with @Before causes that method to be run before each Test method.

24) Explain the execution procedure of the JUnit test API methods?

Ansthe following  is how the JUnit execution procedure works:

  • First of all method annotated as @BeforeClass executes only once
  • Lastly,the method annotated as @AfterClass executes only once
  • Method annotated as @Before executes for each test case but before executing the test case.
  • Method annotated as @After executes for each test case but after the execution of test case
  • In between method annotatated as @Before and method annotated as @After each test case executes
25)  How to compile a JUnit Test Class?
Ans: Compiling a JUnit test class is like compiling any other java classes. The only thing is you need watch out is the JUnit jar file must be included in the classpath.
26) What If a JUnit Test method is declared as "private"?
Ans: If JUnit test method is declared as private it compile fine. But The execution will fail. Because Junit requires that all test methods must be declared as "public".
27) Name some of the JUnit extensions?
Ans: 
JWebUnit
XMLUnit
MockObject
28) What is Cactus?
Ans: Cactus is a simple test framework for unit testing server-side java code. It uses JUnit and extends it. Cactus implements an in-container strategy,meaning that tests are exectuted inside the container.    
29) What is JWebUnit?
Ans: WebUnit is a java-based testing framework for web applications. It wraps existing testing frameworks such as HtmlUnit and Selenium with a unified,simple testing interface to allow you to quickly test the correctness of your web applications.
30) What is XMLUnit?
Ans: It provides a single JUnit extension class, XMLTestCase, and a set of supporting classes.
        

No comments:

Post a Comment

High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...