ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dominique Devienne" <DDevie...@lgc.com>
Subject RE: Introducing AntUnit
Date Thu, 14 Apr 2005 13:53:32 GMT
> From: Stefan Bodewig [mailto:bodewig@apache.org]
> 
> The other part will be an <antunit> task, which will take a build file
> and for each target whose name starts with "test" will
> 
> (1) create an Ant task
> (2) run the target named setUp if present
> (3) run the target
> (4) run the target named tearDown if present

(2) mimicks JUnit, but may not be necessary. I've found personally that
Ant's depends="setUp" attribute on target is enough, and more flexible
when you want to customize the test fixture using several setup targets.

(4) OTOH is useful and great for cleanup directly from Ant.

I use a modified BuildFileTest adapted to call any 'tearDown' target.

    /**
     * Automatically configures the project, inferring the build file to
     * use from the current test case class name.
     *
     * @throws Exception if a Ant build file named after this test case
     *         (with the .xml suffix) cannot be found collocated to that
     *         test case' class file.
     */
    protected void setUp() throws Exception {
        String classname = getClass().getName();
        String resname = '/' + classname.replace('.', '/') + ".xml";
        URL buildfileURL = getClass().getResource(resname);
        File buildfile = new File(new URI(buildfileURL.toString()));
        configureProject(buildfile.getAbsolutePath());
        _buildfile = buildfile;
    }

    /**
     * Automatically calls the target called "tearDown"
     * from the build file tested if it exits.
     */
    protected void tearDown() {
        final String tearDown = "tearDown";
        if (project.getTargets().containsKey(tearDown)) {
            project.executeTarget(tearDown);
        }
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message