Hi All,
With the TCK behind us (thanks again to all who worked so hard on
that) I figured it was a good time to work on getting cactus tests in
place. My thinking behind Cactus is that we need to have the ability
to do in container testing because some of the mock stuff is just too
tedious. As background info I've been working on bug # 233 (empty
date for inputCalendar) and its just too complex to test all the
cases with mocks because of the amount of code that must be written
to setup the mock env.
So I set out to get a cactus test env that I could execute container
side tests in and I've gotten a fair way there.
Here is the big picture of what I've done;
1) Added a cactus and download of the required jars with download-
dependencies
2) Added Cargo to the equation (cargo starts and stops containers
from ant)
3) Added build.dir to the list of properties transfered down to the
subprojects
4) added lots of properties to the tomahawk directory to manage the
cactus configuration
I'm hoping for feedback from Sean on 3 because of the possibility of
breaking something I've not tested fully.
I have tested the 'main' targets, dist-all, release, unit-test-all
and they all work so it should be ok but I wanted to run it by
everyone before
committing.
The Good:
1) Cactus gives us an alternative means to test (in the container)
2) Cargo integration will be a great way to build tests that
automatically invoke the example code on a wide range of containers
with each release. This will help us avoid problems with the various
containers because of a lack of testing.
The Bad:
1) more dependencies
2) we don't seem to have a ground swell of support for testing so
this all might be for nothing
What are you thoughts? Since introduction of JUnit I've not seen any
additional tests being added to the mix. Its a huge task to get test
coverage but I think its worth it, we will significantly reduce the
uncertainty in doing a release if we can get a good set of tests in
place.
I'm working on getting some more JUnit tests in place and would love
to write up what is required if that would help others get started.
Looking forward to your feedback.
TTFN,
-bd-
Here is a patch of what I've changed in build.xml;
Index: /Users/Shared/Applications/Eclipse-3.1/workspace/myfaces-
current/build/build.xml
===================================================================
--- /Users/Shared/Applications/Eclipse-3.1/workspace/myfaces-current/
build/build.xml (revision 290873)
+++ /Users/Shared/Applications/Eclipse-3.1/workspace/myfaces-current/
build/build.xml (working copy)
@@ -28,7 +28,7 @@
Commons Digester package.
[Version 1.5 or later]
- commons-el.jar The path to the JAR file of the
Jakarta
+ commons-el.jar The path to the JAR file of the
Jakarta
Commons EL package.
[Version 1.0 or later]
@@ -86,6 +86,32 @@
+ TESTING PROPERTIES
+ Each of these properties MAY be set in one of the following ways:
+ * on the "ant" command line
+ * in a "build.local.properties" file in the base directory
+ * in a "build.properties" file in your user home directory
+ If not set, testing will not work properly. Reasonable defaults
are used where possible.
+
+ junit.jar The path to the JAR file for JUnit
+ Not known to work with version 4.0 yet.
+ [Version 3.8.1 or later]
+
+ easymock.jar The path to the JAR file for
EasyMock
+ [Version 1.0 or later]
+
+ easymock-classextension.jar The path to the JAR file for
EasyMock
+ [Version 1.0 or later]
+
+ cglib.jar The path to the JAR file for CGLib
used by EasyMock
+ [Version 2.1.2 or later]
+
+ asm.jar The path to the JAR file for ASM
used by EasyMock
+ [Version 1.5.3 or later]
+
+ cargo.jar The path to the JAR file for Cargo
+ [Version 0.6 or later]
+
OPTIONAL PROPERTIES
Each of these properties MAY be set in one of the following ways:
@@ -264,6 +290,15 @@
<pathelement location="${cglib.jar}"/>
<pathelement location="${asm.jar}"/>
</path>
+
+ <path id="cactus.classpath">
+ <path refid="test.classpath"/>
+ <pathelement location="${lib.dir}/aspectjrt.jar"/>
+ <pathelement location="${lib.dir}/cactus.jar"/>
+ <pathelement location="${lib.dir}/commons-httpclient.jar"/>
+ <pathelement location="${lib.dir}/httpunit.jar"/>
+ <pathelement location="${lib.dir}/nekohtml.jar"/>
+ </path>
<!-- ========== Executable Targets
======================================== -->
@@ -373,10 +408,31 @@
usetimestamp="true" ignoreerrors="true"
src="http://www.ibiblio.org/maven/cglib/jars/
cglib-2.1_2.jar"/>
- <get dest="${lib.dir}/asm.jar"
- usetimestamp="true" ignoreerrors="true"
- src="http://www.ibiblio.org/maven/asm/jars/
asm-1.5.3.jar"/>
+ <get dest="${lib.dir}/asm.jar"
+ usetimestamp="true" ignoreerrors="true"
+ src="http://www.ibiblio.org/maven/asm/jars/asm-1.5.3.jar"/>
+ <get dest="${lib.dir}/cargo.jar"
+ usetimestamp="true" ignoreerrors="true"
+ src="http://www.ibiblio.org/maven/cargo/jars/cargo-0.6.jar"/>
+
+ <!-- cactus stuff -->
+ <get dest="${lib.dir}/cactus.jar"
+ usetimestamp="true" ignoreerrors="true"
+ src="http://www.ibiblio.org/maven/cactus/jars/
cactus-13-1.7.1.jar"/>
+ <get dest="${lib.dir}/aspectjrt.jar"
+ usetimestamp="true" ignoreerrors="true"
+ src="http://www.ibiblio.org/maven/aspectj/jars/
aspectjrt-1.2.1.jar"/>
+ <get dest="${lib.dir}/commons-httpclient.jar"
+ usetimestamp="true" ignoreerrors="true"
+ src="http://www.ibiblio.org/maven/commons-httpclient/jars/
commons-httpclient-2.0.2.jar"/>
+ <get dest="${lib.dir}/httpunit.jar"
+ usetimestamp="true" ignoreerrors="true"
+ src="http://www.ibiblio.org/maven/httpunit/jars/
httpunit-1.6.jar"/>
+ <get dest="${lib.dir}/nekohtml.jar"
+ usetimestamp="true" ignoreerrors="true"
+ src="http://www.ibiblio.org/maven/nekohtml/jars/
nekohtml-0.9.1.jar"/>
+
<property name="commons-beanutils.jar" value="$
{lib.dir}/commons-beanutils.jar"/>
<property name="commons-codec.jar" value="$
{lib.dir}/commons-codec.jar"/>
<property name="commons-collections.jar" value="$
{lib.dir}/commons-collections.jar"/>
@@ -401,7 +457,7 @@
<property name="easymock-classextension.jar" value="$
{lib.dir}/easymock-classextension.jar"/>
<property name="cglib.jar" value="$
{lib.dir}/cglib.jar"/>
<property name="asm.jar" value="$
{lib.dir}/ams.jar"/>
-
+ <property name="cargo.jar" value="$
{lib.dir}/cargo.jar"/>
</target>
<!--
@@ -413,6 +469,7 @@
<ant antfile="build/build.xml" target="${target}" dir="../$
{subproject}">
<property name="subproject.dir" value="${basedir}/../$
{subproject}"/>
+ <property name="build.dir" value="${basedir}/../$
{subproject}/build"/>
<property name="temp.dir" value="${basedir}/../$
{subproject}/build/temp"/>
<property name="dist.dir" value="${basedir}/../$
{subproject}/build/dist"/>
<property name="classes.dir" value="${basedir}/../$
{subproject}/build/temp/classes"/>
@@ -501,18 +558,18 @@
<!--
Run unit tests for all subprojects that have them
-->
- <target name="unit-test-all" depends="download-dependencies">
-
+ <target name="unit-test-all" depends="download-dependencies"
+ description="Run all JUnit tests in all subproject">
<ant target="project">
<property name="target" value="unit-test"/>
</ant>
-
</target>
<!--
Compile and run tests in current subproject
-->
- <target name="unit-test" depends="compile" if="test.src.dir"
description="build and run subproject unit tests">
+ <target name="unit-test" depends="compile" if="test.src.dir"
+ description="build and run subproject unit tests">
<mkdir dir="${test.classes.dir}"/>
<mkdir dir="${test.reports.dir}/xml"/>
<mkdir dir="${test.reports.dir}/html"/>
@@ -521,6 +578,8 @@
optimize="${javac.optimize}"
debug="${javac.debug}"
classpathref="test.classpath">
+ <include name="${test.suffix}"/>
+ <exclude name="${cactus.suffix}"/>
</javac>
<junit printsummary="yes" fork="yes" haltonfailure="no">
<classpath>
@@ -545,6 +604,104 @@
</junitreport>
</target>
+ <target name="build-cactus-war" if="has.cactus.tests">
+ <mkdir dir="${cactus.classes.dir}"/>
+ <javac srcdir="${cactus.src.dir}"
+ destdir="${cactus.classes.dir}"
+ optimize="${javac.optimize}"
+ debug="${javac.debug}"
+ classpathref="cactus.classpath">
+ <exclude name="${test.suffix}"/>
+ <include name="${cactus.suffix}"/>
+ </javac>
+ <jar destfile="${cactus.dir}/cactus-tests.jar"
+ basedir="${cactus.classes.dir}">
+ </jar>
+ <war destfile="${cactus.dir}/cactus-app.war"
+ webxml="${build.dir}/cactus-web.xml">
+ <lib dir="${cactus.dir}">
+ <include name="cactus-tests.jar"/>
+ </lib>
+ <lib dir="${lib.dir}">
+ <include name="aspectjrt.jar"/>
+ <include name="cactus.jar"/>
+ <include name="commons-httpclient.jar"/>
+ <include name="httpunit.jar"/>
+ <include name="nekohtml.jar"/>
+ </lib>
+ <lib file="${junit.jar}"/>
+ <lib file="${jsf-api.jar}"/>
+ <lib file="${jsf-impl.jar}"/>
+ <lib file="${tomahawk.jar}"/>
+ <lib file="${commons-beanutils.jar}"/>
+ <lib file="${commons-collections.jar}"/>
+ <lib file="${commons-codec.jar}"/>
+ <lib file="${commons-digester.jar}"/>
+ <lib file="${commons-el.jar}"/>
+ <lib file="${commons-fileupload.jar}"/>
+ <lib file="${commons-lang.jar}"/>
+ <lib file="${commons-logging.jar}"/>
+ <lib file="${commons-validator.jar}"/>
+ <lib file="${jakarta-oro.jar}"/>
+ <lib file="${struts.jar}"/>
+ <zipfileset dir="${build.dir}" fullpath="WEB-INF/classes/
log4j.properties">
+ <include name="cactus-log4j.properties"/>
+ </zipfileset>
+ </war>
+ </target>
+
+ <!--
+ Run unit tests for all subprojects that have them
+ -->
+ <target name="cactus-test-all"
+ description="Run all Cactus tests in all subproject">
+ <ant target="project">
+ <property name="target" value="cactus-test"/>
+ </ant>
+ </target>
+
+ <target name="cactus-test" depends="build-cactus-war"
if="has.cactus.tests"
+ description="run any cactus tests for the current
subproject">
+ <mkdir dir="${tomcat5x.container.dir}"/>
+ <mkdir dir="${cactus.reports.dir}/xml"/>
+ <mkdir dir="${cactus.reports.dir}/html"/>
+ <taskdef resource="cargo.tasks">
+ <classpath>
+ <pathelement location="${cargo.jar}"/>
+ </classpath>
+ </taskdef>
+ <cargo-tomcat5x homeDir="${env.CATALINA_HOME}"
+ output="${tomcat5x.container.dir}/cargo.log" action="start">
+ <configuration id="cargo.tomcat5" dir="$
{tomcat5x.container.dir}">
+ <property name="cargo.logging" value="high"/>
+ <property name="cargo.servlet.port" value="$
{tomcat5x.container.port}"/>
+ <war warFile="${cactus.dir}/cactus-app.war" context="$
{cactus.web.context}"/>
+ </configuration>
+ </cargo-tomcat5x>
+ <copy file="${build.dir}/cactus.properties" todir="$
{cactus.classes.dir}"/>
+ <junit printsummary="yes" fork="yes" haltonfailure="no">
+ <classpath>
+ <path refid="cactus.classpath"/>
+ <pathelement location="${classes.dir}"/>
+ <pathelement location="${cactus.classes.dir}"/>
+ </classpath>
+
+ <formatter type="xml" />
+
+ <batchtest fork="yes" todir="${cactus.reports.dir}/xml">
+ <fileset dir="${cactus.classes.dir}">
+ <include name="**/**Cactus.class" />
+ </fileset>
+ </batchtest>
+ </junit>
+ <junitreport todir="${cactus.reports.dir}/html">
+ <fileset dir="${cactus.reports.dir}/xml">
+ <include name="TEST-*.xml"/>
+ </fileset>
+ <report format="frames" todir="${cactus.reports.dir}/html"/>
+ </junitreport>
+ </target>
+
<!--
Clean all subprojects (plus top-level stuff).
-->
@@ -559,6 +716,8 @@
-->
<target name="clean">
<delete dir="${temp.dir}"/>
+ <delete dir="${tests.dir}"/>
+ <delete dir="${cactus.dir}"/>
<delete dir="${dist.dir}"/>
<delete dir="${release.dir}"/>
</target>