| Target | Description |
|---|
| itest | run integration test(s) manually |
<?xml version="1.0" encoding="UTF-8"?>
<project name="itest">
<description>
+ ==\_/============J=A=V=A=G=E=N===A=N=T===M=O=D=U=L=E=S================= +
+ \(_)/ +
+ -(_)- JUnit Integration Testing on Deployed Apps +
+ /(_)\ +
+ ======================================================================= +
+ Copyright (c) 2002-2005 Outsource Cafe, Inc. All rights reserved. +
+ ======================================================================= +
+
+ Integration test module. Integration tests run after the target module
+ has been deployed (to a web or ejb container). This module is sufficently
+ generic to be used for functional, load and stress testing. Normal
+ unit testing can be combined in the same build by importing utest.xml.
+
+ Common uses for this module include: remote EJB tests, web service tests,
+ authentication/authorization tests, web page link checks, etc.
+
+ By default all tests found in the 'itest' directories ending with the
+ 'ITest' suffix are executed. Overriding the 'itest.batchtest.include' and
+ 'itest.batchtest.exclude' properties allows you to change the default settings.
+ Single tests can be run by assigning the full classname to the 'itestcase'
+ property. Test results can be sent to an html report by setting 'testreports'.
+
+ You can use testcycle.xml to automate the package, deploy, test, undeploy
+ process including starting and stopping the server.
+
+ Public targets:
+ itest - runs integration test(s), optionaly generating reports
+
+ Optional properties:
+ itestcase - when set allows single unit test to be run instead of batchtest
+ testreports - when set test results generate reports
+ itestfork - fork unit tests, default: 'false'
+ itest.updotate.on - if set: skip running tests again if tests are uptodate
+ target.classes.dir - classes to test, defaults to build.classes.dir
+
+ Prerequisit properties:
+ itest.folder - folder name associated with unit tests (test)
+ src.itest.dir - Java unit test source code directory
+ gen.itest.dir - Generated Java unit test source code directory
+ build.itest.dir - destination directory of temporary test artifacts
+ build.itest.classes.dir - destination directory of compiled classes
+ build.itest.metainf.dir - META-INF directory
+ build.test.reports.dir - temp reports directory
+ build.test.docs.dir - test reports directory
+
+ Note: the 'itest' prefix used to avoid target name confilcts with main build file.
+
+ developer: RichardEasterling@OutsourceCafe.com
+ ======================================================================= +
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ =J=A=M===========================================J=A=V=A=G=E=N=.=C=O=M= +
</description>
<property name="ITEST.PRESENT" value="true"></property>
<!-- =================================================================== -->
<!-- Public target: -->
<!-- =================================================================== -->
<target name="itest" depends="itest.run, itest.fail" description="run integration test(s) manually"></target>
<!-- =================================================================== -->
<!-- Exported support targets: -->
<!-- =================================================================== -->
<!-- 'testcycle' uses 'itest.run' to delay failure until server shutdown -->
<target name="itest.run" depends="itest.uptodate, itest.compile, itest.resources, itest.console, itest.report"></target>
<!-- ===================================================================== -->
<!-- properties for both this module and the target test module -->
<!-- ===================================================================== -->
<property name="testtool.name" value="JUnit"></property>
<property name="itest.last.failed.file" location="${build.dir}/.lastitestsfailed"></property>
<property name="itest.fork" value="true"></property>
<property name="target.classes.dir" location="${build.classes.dir}"></property>
<!-- optional properties set in build file:
<property name="utestcase" value="AllITests"/>
<property name="testreports" value="true"/>
-->
<!-- ===================================================================== -->
<!-- test classpaths -->
<!-- ===================================================================== -->
<path id="itest.build.classpath">
<pathelement path="${java.class.path}"></pathelement>
<path refid="dependencies.classpath"></path>
<pathelement location="${junit.jar}"></pathelement>
<pathelement location="${target.classes.dir}"></pathelement>
<pathelement location="${build.itest.classes.dir}"></pathelement>
</path>
<!-- ===================================================================== -->
<!-- patternset to identify integration tests to execute -->
<!-- ===================================================================== -->
<property name="itest.batchtest.include" value="**/*ITest.java"></property>
<patternset id="itest.batchtest.patternset">
<include name="${itest.batchtest.include}"></include>
<exclude name="${utest.batchtest.exclude}"></exclude>
</patternset>
<!-- ===================================================================== -->
<!-- sanity checks -->
<!-- ===================================================================== -->
<condition property="itest.properties.ok">
<and>
<available file="${junit.jar}"></available>
</and>
</condition>
<fail message="JUnit properties error (check jars, etc.)" unless="itest.properties.ok"></fail>
<!-- ===================================================================== -->
<!-- show settings - override 'setup' add-on -->
<!-- ===================================================================== -->
<target name="itest.settings">
<echo>
itestcase = ${itestcase}
testreports = ${testreports}
itest.batchtest.include = ${itest.batchtest.include}
+ ============================================================= +
</echo>
</target>
<!-- ===================================================================== -->
<!-- list unit test build classpath -->
<!-- ===================================================================== -->
<target name="itest.cp">
<pathconvert refid="itest.build.classpath" property="itest.classpath.list" pathsep="${CR}"></pathconvert>
<echo message="+ itest.build.classpath================================= +"></echo>
<echo message="${itest.classpath.list}"></echo>
</target>
<!-- =================================================================== -->
<!-- Logic to skip running unit tests if src and test(s) are uptodate. -->
<!-- Note: Many users can't figure out why their tests are not running -->
<!-- when uptodate is set. To avoid confusion the tests run on every -->
<!-- call unless you explicitly set 'itest.uptodate.on' to 'true'. -->
<!-- =================================================================== -->
<target name="itest.uptodate">
<mkdir dir="${gen.itest.dir}"></mkdir>
<mkdir dir="${src.itest.dir}"></mkdir>
<mkdir dir="${xdoclet.build.java.dir}"></mkdir>
<condition property="itests-uptodate">
<and>
<!-- always run tests unless this property has been set -->
<isset property="itest.uptodate.on"></isset>
<uptodate>
<!--if no changes in target source - compare *.java to *.class timestamps-->
<srcfiles dir="${src.java.dir}" includes="**/*.java"></srcfiles>
<srcfiles dir="${gen.java.dir}" includes="**/*.java"></srcfiles>
<srcfiles dir="${xdoclet.build.java.dir}" includes="**/*.java"></srcfiles>
<mapper type="glob" from="*.java" to="${target.classes.dir}/*.class"></mapper>
</uptodate>
<uptodate>
<!--if no changes in unit test source - compare *.java to *.class timestamps-->
<srcfiles dir="${src.itest.dir}" includes="**/*.java"></srcfiles>
<srcfiles dir="${gen.itest.dir}" includes="**/*.java"></srcfiles>
<mapper type="glob" from="*.java" to="${build.itest.classes.dir}/*.class"></mapper>
</uptodate>
<uptodate>
<!--if no changes in target resources (non-source) - compare timestamps on files in src and classes directories -->
<srcfiles dir="${src.itest.dir}" excludes="**/*.java"></srcfiles>
<srcfiles dir="${gen.itest.dir}" excludes="**/*.java"></srcfiles>
<mapper type="glob" from="*" to="${build.itest.classes.dir}/*"></mapper>
</uptodate>
<not>
<!--always run tests if single unit test class spacified -->
<isset property="itestcase"></isset>
</not>
<or>
<not>
<!-- this check is not applicable to console tests -->
<isset property="testreports"></isset>
</not>
<uptodate>
<!-- run test if any report fragments (compared with test source) are missing or not uptodate-->
<srcfiles dir="${src.itest.dir}" includes="**/*.java"></srcfiles>
<srcfiles dir="${gen.itest.dir}" includes="**/*.java"></srcfiles>
<mapper type="package" from="*ITest.java" to="${build.test.reports.dir}/TEST-*ITest.xml"></mapper>
</uptodate>
</or>
<not>
<!--run tests if last test failed (indicated by this file not being erased)-->
<available file="${itest.last.failed.file}"></available>
</not>
</and>
</condition>
<echo>itests-uptodate = ${itests-uptodate}, testreports = ${testreports}</echo>
<!-- determine which target to run based on 'testreports' property -->
<condition property="skip.itest.console">
<or>
<isset property="testreports"></isset>
<isset property="itests-uptodate"></isset>
</or>
</condition>
<condition property="skip.itest.reports">
<or>
<not>
<isset property="testreports"></isset>
</not>
<isset property="itests-uptodate"></isset>
</or>
</condition>
<!--
<echo>skip.itest.console= ${skip.itest.console}</echo>
<echo>skip.itest.reports = ${skip.itest.reports}</echo>
-->
</target>
<!-- =================================================================== -->
<!-- compiles the test source code -->
<!-- =================================================================== -->
<target name="itest.compile">
<mkdir dir="${build.itest.classes.dir}"></mkdir>
<javac destdir="${build.itest.classes.dir}" source="${compiler.source}" target="${compiler.target}" classpathref="itest.build.classpath" debug="${compiler.debug}" deprecation="${compiler.deprecation}" optimize="${compiler.optimize}" compiler="${compiler.type}" excludes="${compiler.excludes}">
<src path="${gen.itest.dir}"></src>
<src path="${src.itest.dir}"></src>
</javac>
</target>
<!-- =================================================================== -->
<!-- copies test resources to target/itest/classes -->
<!-- =================================================================== -->
<!-- Note: Unfortunately, the POM does not define resources for integration
tests, thus this (probably inadequate) default target. If you use the same
resources for both unit and integration testing then just override this target
to invoke the generated utest.resources target like so:
<target name="itest.resources">
<antcall target="utest.resources">
<param name="build.test.classes.dir" value="${build.itest.classes.dir}"/>
</antcall>
</target>
-->
<target name="itest.resources">
<copy todir="${build.itest.classes.dir}">
<fileset dir="${src.itest.dir}" excludes="**/*.java"></fileset>
<fileset dir="${gen.itest.dir}" excludes="**/*.java"></fileset>
</copy>
</target>
<!-- =================================================================== -->
<!-- run unit test(s) sending results to console -->
<!-- =================================================================== -->
<target name="itest.console" unless="skip.itest.console">
<echo>itestcase = ${itestcase}</echo>
<junit printsummary="true" errorProperty="itest.failed" failureProperty="itest.failed" fork="${itest.fork}">
<classpath refid="itest.build.classpath"></classpath>
<formatter type="plain" usefile="false"></formatter>
<test name="${itestcase}" if="itestcase"></test>
<batchtest todir="${build.test.reports.dir}" unless="itestcase">
<fileset dir="${src.itest.dir}">
<patternset refid="itest.batchtest.patternset"></patternset>
</fileset>
<fileset dir="${gen.itest.dir}">
<patternset refid="itest.batchtest.patternset"></patternset>
</fileset>
</batchtest>
</junit>
<echo message="last build failed tests" file="${itest.last.failed.file}"></echo>
</target>
<!-- =================================================================== -->
<!-- run unit test(s) sending results to html report -->
<!-- =================================================================== -->
<target name="itest.report" unless="skip.itest.reports">
<delete dir="${build.test.docs.dir}" failonerror="false"></delete>
<delete dir="${build.test.reports.dir}" failonerror="false"></delete>
<mkdir dir="${build.test.docs.dir}"></mkdir>
<mkdir dir="${build.test.reports.dir}"></mkdir>
<echo>itestcase = ${itestcase}</echo>
<echo>itest.batchtest.include = ${itest.batchtest.include}</echo>
<junit printsummary="true" errorProperty="itest.failed" failureProperty="itest.failed" fork="${itest.fork}">
<classpath refid="itest.build.classpath"></classpath>
<formatter type="xml"></formatter>
<test name="${itestcase}" todir="${build.test.reports.dir}" if="itestcase"></test>
<batchtest todir="${build.test.reports.dir}" unless="itestcase">
<fileset dir="${src.itest.dir}">
<patternset refid="itest.batchtest.patternset"></patternset>
</fileset>
<fileset dir="${gen.itest.dir}">
<patternset refid="itest.batchtest.patternset"></patternset>
</fileset>
</batchtest>
</junit>
<junitreport todir="${build.test.docs.dir}">
<fileset dir="${build.test.reports.dir}">
<include name="TEST-*.xml"></include>
</fileset>
<report format="noframes" todir="${build.test.docs.dir}"></report>
</junitreport>
<echo message="last build failed tests" file="${itest.last.failed.file}"></echo>
</target>
<!-- =================================================================== -->
<!-- fail if tests failed otherwise erase itest.last.failed.file -->
<!-- =================================================================== -->
<target name="itest.fail">
<echo message="last build failed tests" file="${itest.last.failed.file}"></echo>
<fail message="Unit test(s) failed. Check log and/or reports directory." if="itest.failed"></fail>
<!-- Remove test failed file, as these tests succeeded -->
<delete file="${itest.last.failed.file}" failonerror="false"></delete>
</target>
</project>