Want to shift your career to JUnit? Then there is no need to go and search for Junit Interview Questions and Answers all over. We in the Wisdomjobs have provided all the JUnit Interview Question and Answers and different job role in JUnit in our page. There are various leading companies that offer jobs in various roles are Site Java Developer+junit, Senior Java Developer - Webservices/j2ee, Api Test Engineer/ Api Testing with Java and Junit / C# Developers and many other roles too. To clear any Interview, one must prepare well for the interview to clear it in the very first attempt. To clear JUnit you should have the basic concepts of JAVA. For more details on Junit Jobs, interview Question and Answers visit our site www.wisdomjobs.com.
Answer :
Testing is the process of checking the functionality of the application whether it is working as per requirements.
Question 2. What Is Unit Testing?
Answer :
Unit testing is the testing of single entity (class or method). Unit testing is very essential to every software company to give a quality product to their customers.
Question 3. What Is Manual Testing?
Answer :
Executing the test cases manually without any tool support is known as manual testing.
Question 4. What Is Automated Testing?
Answer :
Taking tool support and executing the test cases by using automation tool is known as automation testing.
Question 5. What Are The Disadvantages Of Manual Testing?
Answer :
Following are the disadvantages of manual testing −
Question 6. What Are The Advantages Of Automated Testing?
Answer :
Following are the advantages of automated testing −
Answer :
JUnit is a Regression Testing Framework used by developers to implement unit testing in Java and accelerate programming speed and increase the quality of code.
Question 8. What Are Important Features Of Junit?
Answer :
Following are the important features of JUnit −
Question 9. What Is A Unit Test Case?
Answer :
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.
Question 10. What Are The Best Practices To Write A Unit Test Case?
Answer :
A formal written unit test case is characterized by a known input and by an expected output, which is worked out before the test is executed. The known input should test a precondition and the expected output should test a postcondition.
There must be at least two unit test cases for each requirement: one positive test and one negative test. If a requirement has sub-requirements, each sub-requirement must have at least two test cases as positive and negative.
Question 11. When Are Unit Tests Written In Development Cycle?
Answer :
Tests are written before the code during development in order to help coders write the best code.
Question 12. Why Not Just Use System.out.println() For Testing?
Answer :
Debugging the code using system.out.println() 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.
Question 13. How To Install Junit?
Answer :
Follow the steps below −
Question 14. Why Does Junit Only Report The First Failure In A Single Test?
Answer :
Reporting multiple failures in a single test is generally a sign that the test does too much and it is too big a unit test. JUnit is designed to work best with a number of small tests. It executes each test within a separate instance of the test class. It reports failure on each test.
Question 15. In Java, Assert Is A Keyword. Won't This Conflict With Junit's Assert() Method?
Answer :
JUnit 3.7 deprecated assert() and replaced it with assertTrue(), which works exactly the same way. JUnit 4 is compatible with the assert keyword. If you run with the -ea JVM switch, assertions that fail will be reported by JUnit.
Question 16. How Do I Test Things That Must Be Run In A J2ee Container (e.g. Servlets, Ejbs)?
Answer :
Refactoring J2EE components to delegate functionality to other objects that don't have to be run in a J2EE container will improve the design and testability of the software. Cactus is an open source JUnit extension that can be used for unit testing server-side java code.
Question 17. Name The Tools With Which Junit Can Be Easily Integrated?
Answer :
JUnit Framework can be easily integrated with either of the followings −
Question 18. What Are The Core Features Of Junit?
Answer :
JUnit test framework provides following important features −
Question 19. What Is A Fixture?
Answer :
Fixture is a fixed state of a set of objects used as a baseline for running tests. The purpose of a 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 following methods −
Question 20. What Is A Test Suite?
Answer :
Test suite means bundle a few unit test cases and run it together. In JUnit, both @RunWith and @Suite annotation are used to run the suite test.
Question 21. What Is A Test Runner?
Answer :
Test runner is used for executing the test cases.
Question 22. What Are Junit Classes? List Some Of Them?
Answer :
JUnit classes are important classes which are used in writing and testing JUnits. Some of the important classes are −
Question 23. What Are Annotations And How Are They Useful In Junit?
Answer :
Annotations are like meta-tags that you can add to you code and apply them to methods or in class. The annotation 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.
Question 24. How Will You Run Junit From Command Window?
Answer :
Follow the steps below −
Question 25. What Is The Purpose Of Org.junit.assert Class?
Answer :
This class provides a set of assertion methods useful for writing tests. Only failed assertions are recorded.
Question 26. What Is The Purpose Of Org.junit.testresult Class?
Answer :
A TestResult collects the results of executing a test case. It is an instance of the Collecting Parameter pattern. The test framework distinguishes between failures and errors. A failure is anticipated and checked for with assertions. Errors are unanticipated problems like an ArrayIndexOutOfBoundsException.
Question 27. What Is The Purpose Of Org.junit.testsuite Class?
Answer :
A TestSuite is a Composite of Tests. It runs a collection of test cases.
Question 28. What Is The Purpose Of @test Annotation In Junit?
Answer :
The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case.
Question 29. What Is The Purpose Of @before Annotation In Junit?
Answer :
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.
Question 30. What Is The Purpose Of @after Annotation In Junit?
Answer :
If you allocate external resources in a Before method you need to release them after the test runs. Annotating a public void method with @After causes that method to be run after the Test method.
Question 31. What Is The Purpose Of @beforeclass Annotation In Junit?
Answer :
Annotating a public static void method with @BeforeClass causes it to be run once before any of the test methods in the class.
Question 32. What Is The Purpose Of @afterclass Annotation In Junit?
Answer :
This will perform the method after all tests have finished. This can be used to perform clean-up activities.
Question 33. What Is @ignore Annotation And How Is This Useful?
Answer :
Following are some of the usefulness of @Ignore annotation −
You can easily identify all @Ignore annotations in the source code, while unannotated or commented out tests are not so simple to find.
There are cases when you can't fix a code that is failing, but you still want to method to be around, precisely so that it does not get forgotten. In such cases @Ignore makes sense.
Question 34. Explain The Execution Procedure Of The Juint Test Api Methods?
Answer :
Following is how the JUnit execution procedure works −
Question 35. What Is The Purpose Of Org.junit.junitcore Class?
Answer :
The test cases are executed using JUnitCore class. JUnitCore is a facade for running tests. It supports running JUnit 4 tests, JUnit 3.8.x tests, and mixtures.
Question 36. How To Simulate Timeout Situation In Junit?
Answer :
Junit provides a handy option of Timeout. If a test case takes more time than specified number of milliseconds then Junit will automatically mark it as failed. The timeout parameter is used along with @Test annotation.
Question 37. How Can You Use Junit To Test That The Code Throws Desired Exception?
Answer :
JUnit provides a option of tracing the Exception handling of code. You can test if a code throws desired exception or not. The expected parameter is used along with @Test annotation as follows − @Test(expected)
Question 38. What Are Parameterized Tests?
Answer :
Junit 4 has introduced a new feature Parameterized tests. Parameterized tests allow developer to run the same test over and over again using different values.
Question 39. How To Create Parameterized Tests?
Answer :
There are five steps, that you need to follow to create Parameterized tests−
Question 40. How Do You Use Test Fixtures?
Answer :
Fixtures is a fixed state of a set of objects used as a baseline for running tests. The purpose of a 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 −
Question 41. How To Compile A Junit Test Class?
Answer :
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.
Question 42. What Happens If A Junit Test Method Is Declared As "private"?
Answer :
If a JUnit test method is declared as "private", it compiles successfully. But the execution will fail. This is because JUnit requires that all test methods must be declared as "public".
Question 43. How Do You Test A "protected" Method?
Answer :
When a method is declared as "protected", it can only be accessed within the same package where the class is defined. Hence to test a "protected" method of a target class, define your test class in the same package as the target class.
Question 44. How Do You Test A "private" Method?
Answer :
When a method is declared as "private", it can only be accessed within the same class. So there is no way to test a "private" method of a target class from any test class. Hence you need to perform unit testing manually. Or you have to change your method from "private" to "protected".
Question 45. What Happens If A Junit Test Method Is Declared To Return "string"?
Answer :
If a JUnit test method is declared to return "String", the compilation will pass ok. But the execution will fail. This is because JUnit requires that all test methods must be declared to return "void".
Question 46. Can You Use A Main() Method For Unit Testing?
Answer :
Yes you can test using main() method. One obvious advantage seems to be that you can whitebox test the class. That is, you can test the internals of it (private methods for example). You can't do that with unit-tests. But primarily the test framework tests the interface and the behavior from the user's perspective.
Question 47. Do You Need To Write A Test Class For Every Class That Needs To Be Tested?
Answer :
No. We need not write an independent test class for every class that needs to be tested. If there is a small group of tests sharing a common test fixture, you may move those tests to a new test class.
Question 48. When Are Tests Garbage Collected?
Answer :
The test runner holds strong references to all Test instances for the duration of the test execution. This means that for a very long test run with many Test instances, none of the tests may be garbage collected until the end of the entire test run. Explicitly setting an object to null in the tearDown() method, for example, allows it to be garbage collected before the end of the entire test run.
Question 49. What Is A Mock Object?
Answer :
In a unit test, mock objects can simulate the behavior of complex, real (non-mock) objects and are therefore useful when a real object is impractical or impossible to incorporate into a unit test.
Question 50. Explain Unit Testing Using Mock Objects?
Answer :
The common coding style for testing with mock objects is to −
Question 51. Name Some Of The Junit Extensions?
Answer :
Following are the JUnit extensions −
Answer :
Cactus is a simple test framework for unit testing server-side java code (Servlets, EJBs, Tag Libs, Filters). The intent of Cactus is to lower the cost of writing tests for server-side code. It uses JUnit and extends it. Cactus implements an in-container strategy, meaning that tests are executed inside the container.
Question 53. What Are The Core Components Of Cactus?
Answer :
Cactus Ecosystem is made of several components −
Question 54. What Is Jwebunit?
Answer :
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.
Question 55. What Are The Advantages Of Using Jwebunit?
Answer :
JWebUnit provides a high-level Java API for navigating a web application combined with a set of assertions to verify the application's correctness. This includes navigation via links, form entry and submission, validation of table contents, and other typical business web application features.
The simple navigation methods and ready-to-use assertions allow for more rapid test creation than using only JUnit or HtmlUnit. And if you want to switch from HtmlUnit to other plugins such as Selenium (available soon), there is no need to rewrite your tests.
Answer :
XMLUnit provides a single JUnit extension class, XMLTestCase, and a set of supporting classes.
Question 57. What Is The Use Of Supporting Classes In Xmlunit?
Answer :
Supporting classes allow assertions to be made about−
JUnit Related Tutorials |
|
---|---|
Core Java Tutorial | Java-Springs Tutorial |
Selenium Tutorial | Bugzilla Bug Tracking System Tutorial |
JUnit Tutorial | Log4j Tutorial |
Apache Ant Tutorial |
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.