Skip to Main Content
Ant: The Definitive Guide, 2nd Edition
book

Ant: The Definitive Guide, 2nd Edition

by Steve Holzner
April 2005
Intermediate to advanced content levelIntermediate to advanced
336 pages
7h 20m
English
O'Reilly Media, Inc.
Content preview from Ant: The Definitive Guide, 2nd Edition

Running Test Cases

To run the JUnit test cases, add a test target to the build file introduced at the beginning of the chapter, and make the main target depend on the test target as part of the build process:

            <target name="main" depends="init, compile, test, compress, deploy">
        <echo>
            ${message}
        </echo>
    </target>

The test target will run the six targets you're going to create in this chapter:

    <property name="testsOK" value="Tested OK...." />
        .
        .
        .
    <target name="test" depends="test1, test2, test3, test4, test5, test6">
            <echo>
            ${testsOK}
            </echo>
            </target>

If you're not using Ant or a Java IDE, you usually run JUnit tests from the command line and use the junit.textui.TestRunner class like this, testing the example class created earlier in the chapter, org.antbook.Project:

%java junit.textui.TestRunner org.antbook.Project

You can do essentially the same thing in Ant using the java task, and that looks like this in the build file for the first test task, test1. Note that I'm adding junit.jar to the classpath:

    <target name="test1" depends="compile">
        <java fork="true" 
            classname="junit.textui.TestRunner" 
            classpath="${ant.home}/lib/junit.jar;.">
            <arg value="org.antbook.Project"/>
        </java>
    </target>

Here's what this task looks like when it's running:

test1:
     [java] ...
     [java] Time: 0.01

     [java] OK (3 tests)

Each dot (.) indicates a test case that's running, and three test cases are in the example. As you can see from the last line, the tests all passed OK, but this isn't exciting and it doesn't ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ant: The Definitive Guide

Ant: The Definitive Guide

Eric M. Burke, Jesse Tilly
Tomcat: The Definitive Guide, 2nd Edition

Tomcat: The Definitive Guide, 2nd Edition

Jason Brittain, Ian F. Darwin
Ant in Action

Ant in Action

Erik Hatcher, Steve Loughran
CMake Cookbook

CMake Cookbook

Radovan Bast, Roberto Di Remigio

Publisher Resources

ISBN: 0596006098Supplemental ContentErrata Page