41.What happens if a JUnit Test Method is Declared as "private"?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". 42.How do you test a "protected" method?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. 43.How do you test a "private" method?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". 44.What happens if a JUnit test method is declared to return "String"?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". 45.Can you use a main Method for Unit Testing?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 privatemethodsforexample. You can't do that with unit-tests. But primarily the test framework tests the interface and the behavior from the user's perspective. 46.Do you need to write a test class for every class that needs to be tested?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. 47.When are tests garbage collected?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. 48.What is a Mock Object?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.
Following are the JUnit extensions−
49.What is Cactus?Cactus is a simple test framework for unit testing server-side java code Servlets, EJBs, TagLibs, 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. 50.What are the core components of Cactus?Cactus Ecosystem is made of several components−
51.What is JWebUnit?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. 52.What are the advantages of using JWebUnit?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. 53.What is XMLUnit?XMLUnit provides a single JUnit extension class, XMLTestCase, and a set of supporting classes. 54.What is the use of supporting classes in XMLUnit?Supporting classes allow assertions to be made about−
55.?
56.?
57.?
58.?
59.?
60.?
|