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

Chapter 5. Testing Builds with JUnit

This chapter is about a crucial aspect of the build processtesting build results before deploying them. It doesn't make sense to deploy a build that has been broken, and using the JUnit framework with Ant, you can run tests on your code and deploy a build only if it satisfies those tests. This is a great way to make sure changes to your code haven't broken anything.

To test the results of a build automatically, you'll need to use one of Ant's most powerful optional tasks: junit. This task is part of the repertoire of every serious Ant developer, especially those working in teams. If someone else on your project has broken your code, you should know about it before you deploy or upload to a shared code repository, and junit will let you know about these problems automatically.

To demonstrate how JUnit works with Ant in this chapter, we're going to use Project.java, shown in Example 5-1, as a guinea pig.

Example 5-1. A simple Project file

package org.antbook;

public class Project 
{
    public Project (String name) 
    {

    }
    
    public boolean returnTrue( ) 
    {
        return true;
    }

    public int return4( ) 
    {
        return 2 + 2;
    }

    public Object returnObject( ) 
    {
        return new Integer(1);
    }

    public static void main(String args[]) 
    {
        Project project = new Project("project");
        System.out.println(project.returnTrue( ));
        System.out.println(project.return4( ));
        System.out.println(project.returnObject( ));
    }
}

This application, Project.java, has three simple methods, each of which returns a value: ...

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