The largest Interview Solution Library on the web


Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

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.
Explain unit testing using Mock Objects.
The common coding style for testing with mock objects is to−

  • Create instances of mock objects.
  • Set state and expectations in the mock objects.
  • Invoke domain code with mock objects as parameters.
  • Verify consistency in the mock objects.
Name some of the JUnit Extensions.
Following are the JUnit extensions−
  • Cactus
  • JWebUnit
  • XMLUnit
  • MockObject

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−

  • Cactus Framework is the heart of Cactus. It is the engine that provides the API to write Cactus tests.
  • Cactus Integration Modules are front ends and frameworks that provide easy ways of using the Cactus Framework Antscripts, Eclipseplugin, Mavenplugin.

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.
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 availablesoon, there is no need to rewrite your tests.

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−

  • The differences between two pieces of XML viaDiffandDetailedDiffclasses.
  • The validity of a piece of XML viaValidatorclass.
  • The outcome of transforming a piece of XML using XSLT viaTransformclass.
  • The evaluation of an XPath expression on a piece of XML
  • viaclassesimplementingtheXpathEngineinterface.
  • Individual nodes in a piece of XML that are exposed by DOM Traversal viaNodeTestclass.

55.?

56.?

57.?

58.?

59.?

60.?

« Previous | 0 | 1 | 2 | 3 | 4 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com