Q1. What is JUnit?
JUnit is a testing framework for unit testing. It uses Java as a programming platform, and it is an Open Source Software managed by the JUnit.org community.
Q2. What is Unit Test Case?
Unit Test Case is a part of the code that ensures that the another part of code (method) behaves as expected. For each requirement, there must be at least two test cases one negative test and one positive test.
Q3. List important features of JUnit?
The important features of JUnit −
Installation steps for JUnit :
set CLASSPATH=%CLASSPATH%;%JUNIT_HOME%\junit.jar
java org.junit.runner.JUnitCore org.junit.tests.AllTests
Q5. How you can write a simple JUnit test case?
Determine one or more public test XYZ() methods that exercise the objects under test and assert expected results.
Q6. What are parameterized tests?
Parameterized tests enable developer to perform the same test over and again using different values.
Q7. What is the difference between JUnit and TestNG?
JUnit | TestNG |
|
|
Q8. What are the different methods of exception handling in JUnit?
Different methods of exception handling in JUnit are:
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.
Q10. What is ignore test in JUnit?
When your code is not ready, and it would fail if executed then you can use @Ignore annotation.
Q11. Mention some useful JUnit extensions?
JUnit extensions include
Q12. Explain who should use JUnit – a developer or tester? Why you use JUnit to test your code?
JUnit is more often used by developers to implement unit tests in JAVA. It is designed for unit testing that is more a coding process and not a testing process. However, many testers and QA engineers use JUnit for unit testing.
JUnit is used because
Q13. What is JUnitCore Class?
JUnitCore class is an inbuilt class in JUnit package; it is based on Façade design pattern, this class is used to run only definite test classes only.
Following is how the JUnit execution procedure works −
Q14. How you can run JUnit from the command window?
To run JUnit from the command window, you have to follow the steps
Q15. What are JUnit Classes? List some of them.
JUnit classes are important classes which are used in writing and testing JUnits. Some of the important classes are −
Q16. What are annotations and how are they useful in JUnit?
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.
Q17. How will you run JUnit from command window?
Follow the steps below −
Q18. What are the disadvantages of manual testing?
Q19. What are the advantages of automated testing?
Q20. Name the tools with which JUnit can be easily integrated.
JUnit Framework can be easily integrated with either of the followings −
Q21. What is a fixture?
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:
Q22. What is a test suite?
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.
Q23. What is a test runner?
Test runner is used for executing the test cases.
Q24. What is the purpose of org.junit.TestResult class?
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.
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.
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.
Q27. Why does JUnit only report the first failure in a single test?
There is no particular answer for this question, the main reason it does it like this to make the testing process simple and easy. Even though the failures are more than one it only reports the first failure, resolving which may implicitly resolve other unreported failures too.
Q28. Is it possible to pass command-line arguments to a test execution?
Yes, It’s possible to pass command line arguments to a test execution –
You should use this command:
-D JVM command-line options
Q29. Can we change return type of JUnit test method from void to some other type?
Ideally you should not do this. All the JUnit test methods should have a void return type. If you change the return type then the test method would not be considered as a test method and would be ignored during execution of tests.
Q30. The methods Get () and Set () should be tested for which conditions?
Unit tests performed on java code should be designed to target areas that might break. Since the set() and get() methods on simple data types are unlikely to break, there is no need to test them explicitly. On the other hand, set() and get() methods on complex data types are vulnerable to break. So they should be tested.