ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chane...@netscape.com (Patrick Chanezon)
Subject Re: PATCH: JUnit task
Date Wed, 22 Mar 2000 22:04:30 GMT
Excellent idea Thomas.
We use Ant on our project and we also use JUnit. Actually I was planning to add the
task myself later on, so thanks for having done it and I'm very interested into
seeing that task integrated into ant.

P@

Thomas Haas wrote:

> Hi all
>
> Beside builds we want also run tests by ant. Therefor I provide a ant
> task to run tests written using the JUnit framework.
>
> The JUnit framework was initially created by Erich Gamma and Kent Beck
> and is intended to ease unit tests.
> More infos on JUnit can be found at:
>  ftp://www.armaties.com/D/home/armaties/ftp/TestingFramework/JUnit/
>
> If others are interested in a JUnit task, I ask the committers to apply
> and commit the patch.
> Until now, no patch for index.html is available. I will provide one, if
> this optional task gets applied and committed.
>
> Any feedback is welcomed.
>
> Thanky you
> - tom
>
>   ------------------------------------------------------------------------
> --- defaults.properties.orig    Wed Mar 22 05:20:52 2000
> +++ defaults.properties Wed Mar 22 22:16:16 2000
> @@ -31,6 +31,7 @@
>  script=org.apache.tools.ant.taskdefs.optional.Script
>  netrexxc=org.apache.tools.ant.taskdefs.optional.NetRexxC
>  renameext=org.apache.tools.ant.taskdefs.optional.RenameExtensions
> +junitrun=org.apache.tools.ant.taskdefs.optional.JUnitRunner
>
>  # deprecated ant tasks (kept for back compatibility)
>  javadoc2=org.apache.tools.ant.taskdefs.Javadoc
>
>   ------------------------------------------------------------------------
> --- JUnitRunner.java.orig       Wed Mar 22 22:17:04 2000
> +++ JUnitRunner.java    Wed Mar 22 22:56:54 2000
> @@ -0,0 +1,132 @@
> +/*
> + * The Apache Software License, Version 1.1
> + *
> + * Copyright (c) 1999 The Apache Software Foundation.  All rights
> + * reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + *
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in
> + *    the documentation and/or other materials provided with the
> + *    distribution.
> + *
> + * 3. The end-user documentation included with the redistribution, if
> + *    any, must include the following acknowlegement:
> + *       "This product includes software developed by the
> + *        Apache Software Foundation (http://www.apache.org/)."
> + *    Alternately, this acknowlegement may appear in the software itself,
> + *    if and wherever such third-party acknowlegements normally appear.
> + *
> + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
> + *    Foundation" must not be used to endorse or promote products derived
> + *    from this software without prior written permission. For written
> + *    permission, please contact apache@apache.org.
> + *
> + * 5. Products derived from this software may not be called "Apache"
> + *    nor may "Apache" appear in their names without prior written
> + *    permission of the Apache Group.
> + *
> + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
> + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
> + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + * ====================================================================
> + *
> + * This software consists of voluntary contributions made by many
> + * individuals on behalf of the Apache Software Foundation.  For more
> + * information on the Apache Software Foundation, please see
> + * <http://www.apache.org/>.
> + */
> +
> +package org.apache.tools.ant.taskdefs.optional;
> +
> +import org.apache.tools.ant.taskdefs.Java;
> +import org.apache.tools.ant.BuildException;
> +
> +import junit.textui.TestRunner;
> +import junit.textui.TextTestResult;
> +
> +
> +/**
> + * Ant task to run JUnit tests.
> + *
> + * JUnit is a framework to create unit test. It has been initially
> + * created by Erich Gamma and Kent Beck.
> + * JUnit can be found at <a
> + * href="ftp://www.armaties.com/D/home/armaties/ftp/TestingFramework/JUnit/"
> + * >ftp://www.armaties.com/D/home/armaties/ftp/TestingFramework/JUnit/</a>.
> + * <p>
> + * This ant task runs a single TestCase. By default it spans a new Java VM
> + * to prevent interferences between different testcases, unless
> + * <code>fork</code> has been disabled.
> + *
> + * @author Thomas Haas
> + */
> +public class JUnitRunner extends Java {
> +
> +    private String junit = null;
> +    private String classpath = null;
> +
> +    /**
> +     * Set the path to junit classes.
> +     * @param junit path to junit classes.
> +     */
> +    public void setJunit(String junit) {
> +        this.junit = junit;
> +    }
> +
> +    /**
> +     * Set the classpath to be used by the testcase.
> +     * @param classpath the classpath used to run the testcase.
> +     */
> +    public void setClasspath(String classpath) {
> +        this.classpath = classpath;
> +    }
> +
> +    /**
> +     * The testcase, which must be subclass of
> +     * <code>junit.framework.Test</code>.
> +     * @param testcase the testcase to run.
> +     */
> +    public void setTestcase(String testcase) {
> +        setArgs(testcase);
> +    }
> +
> +
> +    /**
> +     * Creates a new JUnitRunner and enables fork of a new Java VM.
> +     */
> +    public JUnitRunner() {
> +        setFork("on");
> +        setClassname("junit.textui.TestRunner");
> +    }
> +
> +    /**
> +     * Runs the testcase.
> +     */
> +    public void execute() throws BuildException {
> +        if (junit != null) {
> +            if (classpath == null) {
> +                super.setClasspath(junit);
> +            } else {
> +                super.setClasspath(classpath + ":" + junit);
> +            }
> +        }
> +        super.execute();
> +    }
> +
> +}
>
>   ------------------------------------------------------------------------
> --- build.xml.orig      Wed Mar 22 23:00:18 2000
> +++ build.xml   Wed Mar 22 22:57:58 2000
> @@ -30,6 +30,7 @@
>
>      <available property="bsf.present" classname="com.ibm.bsf.BSFManager" />
>      <available property="netrexx.present" classname="netrexx.lang.Rexx" />
> +    <available property="junit.present" classname="junit.textui.TestRunner" />
>
>      <!-- Give user a chance to override without editing this file
>           (and without typing -D each time it compiles it -->
> @@ -56,6 +57,7 @@
>             optimize="on" >
>        <exclude name="**/Script.java" unless="bsf.present" />
>        <exclude name="**/NetRexxC.java" unless="netrexx.present" />
> +      <exclude name="**/JUnitRunner.java" unless="junit.present" />
>      </javac>
>    </target>
>

--
Patrick Chanezon, Vortex - Portal/EServices Technical Lead
Netscape Communications Corp. - http://people.netscape.com/chanezon/
Opinions are my own.

"Ouais, n'empêche qu'à la retraite de Russie, c'est les mecs qu'étaient à la traîne
qu'ont été repassés..." - Michel Audiard - Les Tontons Flingueurs


Mime
View raw message