Thursday, April 21, 2011

Unit Testing Frameworks

JUnit framework helps us to write and execute unit testing programs to test Java applications. We write a test case for each business method, and business logic. Sometimes we write many test cases for testing a single business method depending on the permutations and combinations to check that business logic. We also write test cases for constructors when business logic present in Constructor of a Class. We also write test cases for private methods when they have business logic. The Thumb Rule of unit test cases is: We write test case for testing business logic, where ever it present.

Unit testing applications helps us to:
Ø  To provide high-quality software.
Ø  Improve the developer’s confidence and customer’s satisfaction.
Ø  Test very big applications and business logic in a single click.
Ø  Make sure that the applications to perform consistently in the same way.
Ø  Provide a proof of the application unit testing and metrics.

Junit is sufficient for writing Unit testing applications in Java. But for writing Unit testing applications in J2EE environment we have few other frameworks. We have very good frameworks in Java/J2EE for writing Junit test cases.

Below are few frameworks. These are the extensions to the JUnit framework.

v  Cactus :
For testing server side programs like Servlet, EJB etc., The tests are executed in the Container. Hence the tests executed while server running.

v  JMock:
This framework supports TDD(Test-Driven-Development) for writing java code with mock objects.

v  Shale:
Shale framework provides mock objects for testing server-side java components in absence of container. Shale provides mock object libraries and base classes for creating Junit test cases. This focused on making easy to write test cases for Servlet. JSF, ViewControllers.

v  EasyMock:
This is a mock framework which provides mock objects to create Junit test cases for given interfaces. This provides an easy way to use mock objects. Easy mock provides mock objects for any given interfaces.

This is a light weight framework for writing Unit testing applications in J2EE environment. It supports servlet, filters, jstl, EJB,JMS, JCA, JDBC.

v  DBUnit :
This is a mock framework which provides mock objects to test Database programs. This provides mock objects for Connection, Statement, ResultSet etc.

No comments:

Post a Comment