[BACK]

JUnit and Enhydra

 

Unit Test is an excellent way to ensure the software quality and is an essential part of the popular lightweight methodology termed eXtreme Programming (XP). This article introduce the use of Java based Unit Test framework JUnit and how to apply JUnit to Enhydra.

Before we started, there are three approach to use Unit Test in a server environment best categorized by the Cactus's (jakarta.apache.org/cactus) introduction paper.

Type 1 : code logic unit testing

Type 1 can be satisfied with the typical programming style in JUnit or more advance style like mockobjects (www.mockobjects.com).

Type 2 : integration unit testing

Type 2 require the in container (server) testing of the codes integrated with the server's runtime functionality and other components like database. Cactus framework and the JUnit for Enhydra in this article falls into this category.

Type 3 : functional unit testing

Type 3 is black box unit testing of the system. A good example of this is httpunit (http://sourceforge.net/projects/httpunit) which simulate a Web client over http connection to test the returns value from a servlet execution.

We started the development of JUnit for Enhydra in early 2000 when we started experimenting XP in our development. It's eXtreme Programming, not Windows XP. ;) Developing with Enhydra SuperServlet framework, we want a seamless integration between JUnit with Enhydra. Further, as we are just starting with XP and bringing JUnit framework, we do not want to introduce overhead in moving from JUnit to JUnit for Enhydra. We set up the following requirement for the JUnit for Enhydra project.

  1. Maintain the same programming style as JUnit and uses out of box JUnit without modification to its core class.
  2. Maintain the same command set as JUnit in running JUnit and make all three TestRunner available (text, awt and swing).

The result is the JUnit for Enhydra that can be downloaded from http://www.d11e.com/enhydra. The README included in the package is the only document available and contains instruction of setting up runtime. Since it follows the same style of test case writing as JUnit, you can find out about test case programming from JUnit testing site at www.junit.org.

Adding unit testing to development has significant improvement of our code quality and development speed. A small investment on writing test case yield big payoff in later stage when the requirements start changes and we can maintain a fast pace of programming without much worry of breaking working code.

Happy Unit Testing.

[TOP]
Legal Notices ---- Privacy Policy