Browse DevX
Sign up for e-mail newsletters from DevX


Build a Java Web App Using HttpUnit and the Test-driven Methodology, Part I : Page 2

The HttpUnit client API complements JUnit functionality to provide thorough Web testing capability. This first article of a two-part series breaks down how HttpUnit delivers these features and walks you through a step-by-step setup of a test-driven environment.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Build and Implement an Electronic Phone List
Now proceed through the development cycle using HttpUnit. This article guides you step by step from nothing to having the completed code. You start out with the idea to build an electronic phone list. Your first implementation step (i.e., the part after business requirement solicitation and application design) should be to create the directory tree and write up a foundational build.xml file so that you can begin coding and testing.

First, delete the phonelist directory tree and the phonelist.tgz archive with the following commands:

rm -fr ~/projects/phonelist rm -f ~/phonelist.tgz

Now you are at the same point you would be at if you had just started a software project. Create the directory tree to house the files you will create with the following commands:

mkdir ~/projects/phonelist cd ~/projects/phonelist mkdir src mkdir src/web mkdir src/WEB-INF mkdir src/WEB-INF/classes mkdir src/WEB-INF/classes/com mkdir src/WEB-INF/classes/com/abcinc mkdir src/WEB-INF/classes/com/abcinc/phonelist mkdir src/test mkdir src/test/com mkdir src/test/com/abcinc mkdir src/test/com/abcinc/phonelist mkdir src/test/com/abcinc/phonelist/test

The next step is to create a rudimentary build.xml file so that you can incrementally develop and test with simple, single-line commands that perform automated builds and tests. Type the following into a file called build.xml in the ~/projects/phonelist directory:

<project name="Phone List Application" basedir="."> <target name="init"> <property name="tomcat.install.dir" value="/home/wchao/packages/jakarta-tomcat-4.1.27"/> <property name="struts.install.dir" value="/home/wchao/packages/jakarta-struts-1.1"/> <property name="src.dir" value="${basedir}/src"/> <property name="build.dir" value="${basedir}/build"/> <property name="war.base.name" value="phonelist"/> <property name="deploy.dir" value="${tomcat.install.dir}/webapps"/> <path id="base.path"> <fileset dir="${tomcat.install.dir}/common/lib"> <include name="*.jar"/> </fileset> <fileset dir="${struts.install.dir}/lib"> <include name="*.jar"/> </fileset> </path> <property name="classpath" refid="base.path"/> </target> </project>

Make sure you change the values of the tomcat.install.dir and struts.install.dir properties so that they accurately reflect the locations of Tomcat and Struts. Save what you have now. You have just typed in an initialization target (target, you may recall, is Ant parlance for a series of related instructions packaged together as one unit). The initialization target defines properties you will use later, such as the location of Tomcat, the location of external libraries, and the locations of the source files.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date