Java Reference
In-Depth Information
<batchtest todir="${target.report.dir}">
<fileset dir="${src.test.dir}">
<include name="**/${tests}.java"/>
<exclude name="**/Test*All.java"/>
</fileset>
</batchtest>
<classpath>
<pathelement location="${target.classes.java.dir}"/>
<pathelement location="${target.classes.test.dir}"/>
</classpath>
</junit>
</target>
[...]
<target name="clean">
<delete dir="${target.dir}"/>
</target>
</project>
The
tests
property defines
B
the class name pattern used by the
batchtest
element
C
later in the listing. Defining this property allows us to override it from the com-
mand line or by another property definition. This allows us, for instance, to run a sin-
gle test case or provide a value that runs a narrower set of tests. This technique
provides us a shortcut to run the test for any given class we're working on while leav-
ing the default value to execute the full set of tests. The following example executes
only the
TestDefaultController
test case:
C
ant -Dtests=TestDefaultController test
The
batchtest
element
C
makes the
test
target and our build more flexible. It's
always a good practice to include a
clean
target to remove all build-generated files.
Doing so lets us build from first principles (in our case, Java source files), removing
potential side effects from obsolete classes. Typically, a
dist
(for
distribution
) target
generates all project distributable files and depends on the
clean
target.
You should give thought to your test class names such that you can match them
using a reasonable pattern. Depending on your language background, you may
choose to prefix or postfix your class names with
Test
or
TestCase
, for example,
DatabaseAccessorTest
.
Are automated unit tests a panacea?
In brief, no. Although automated tests can find a significant number of bugs, man-
ual testing is still required to find as many bugs as possible. In general, automated
regression tests catch 15-30 percent of all bugs found; manual testing finds the
other 70-85 percent.
Are you sure about that?
Some test-first enthusiasts are now reporting remarkably low numbers of bug
counts, approximately one to two per month or fewer. Formal studies need to sub-
stantiate these reports. Your mileage will definitely vary.