Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.tools.ant.taskdefs.optional.junit
Class JUnitTask

    java.lang.Object
      |
      +--org.apache.tools.ant.Task
            |
            +--org.apache.tools.ant.taskdefs.optional.junit.JUnitTask

public class JUnitTask
extends Task

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 http://www.junit.org.

To spawn a new Java VM to prevent interferences between different testcases, you need to enable `fork`.

Author:
  Thomas Haas, Stefan Bodewig, Stephane Bailliez

Fields inherited from class org.apache.tools.ant.Task
`description, location, project, target, taskName, taskType, wrapper`

Constructor Summary
`JUnitTask()` Creates a new JUnitRunner and enables fork of a new Java VM.

Method Summary
`void` | `addFormatter(FormatterElement fe)` Add a new formatter to all tests of this task.
`void` | `addSysproperty(Environment.Variable sysp)` Add a nested sysproperty element.
`void` | `addTest(JUnitTest test)` Add a new single testcase.
`protected java.util.Enumeration` | `allTests()`
`BatchTest` | `createBatchTest()` Create a new set of testcases (also called ..batchtest) and add it to the list.
`Path` | `createClasspath()`
`Commandline.Argument` | `createJvmarg()` Create a new JVM argument.
`protected ExecuteWatchdog` | `createWatchdog()`
`void` | `execute()` Runs the testcase.
`protected void` | `execute(JUnitTest test)`
`protected java.io.OutputStream` | `getDefaultOutput()` get the default output for a formatter.
`protected java.util.Enumeration` | `getIndividualTests()` Merge all individual tests from the batchtest with all individual tests and return an enumeration over all `JUnitTest`.
`protected java.io.File` | `getOutput(FormatterElement fe, JUnitTest test)` return the file or null if does not use a file
`void` | `setDir(java.io.File dir)` The directory to invoke the VM in.
`void` | `setFork(boolean value)` Tells whether a JVM should be forked for each testcase.
`void` | `setHaltonerror(boolean value)` Tells this task to halt when there is an error in a test.
`void` | `setHaltonfailure(boolean value)` Tells this task to halt when there is a failure in a test.
`void` | `setJvm(java.lang.String value)` Set a new VM to execute the testcase.
`void` | `setMaxmemory(java.lang.String max)` Set the maximum memory to be used by all forked JVMs.
`void` | `setPrintsummary(boolean value)` Tells whether the task should print a short summary of the task.
`void` | `setTimeout(java.lang.Integer value)` Set the timeout value (in milliseconds).

Methods inherited from class org.apache.tools.ant.Task
`getDescription, getLocation, getOwningTarget, getProject, getRuntimeConfigurableWrapper, getTaskName, init, log, log, maybeConfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### JUnitTask

    public JUnitTask()
              throws java.lang.Exception

  Creates a new JUnitRunner and enables fork of a new Java VM.

Method Detail

### setHaltonerror

    public void setHaltonerror(boolean value)

  Tells this task to halt when there is an error in a test. this property is applied on all BatchTest (batchtest) and JUnitTest (test) however it can possibly be overridden by their own properties.
  Parameters:
    `value` - `true` if it should halt, otherwise `false```

### setHaltonfailure

    public void setHaltonfailure(boolean value)

  Tells this task to halt when there is a failure in a test. this property is applied on all BatchTest (batchtest) and JUnitTest (test) however it can possibly be overridden by their own properties.
  Parameters:
    `value` - `true` if it should halt, otherwise `false```

### setFork

    public void setFork(boolean value)

  Tells whether a JVM should be forked for each testcase. It avoids interference between testcases and possibly avoids hanging the build. this property is applied on all BatchTest (batchtest) and JUnitTest (test) however it can possibly be overridden by their own properties.
  Parameters:
    `value` - `true` if a JVM should be forked, otherwise `false```
  See Also:
    `setTimeout(Integer)`, `#haltOntimeout(boolean)`

### setPrintsummary

    public void setPrintsummary(boolean value)

  Tells whether the task should print a short summary of the task.
  Parameters:
    `value` - `true` to print a summary, `false` otherwise.
  See Also:
    `SummaryJUnitResultFormatter`

### setTimeout

    public void setTimeout(java.lang.Integer value)

  Set the timeout value (in milliseconds). If the test is running for more than this value, the test will be canceled. (works only when in 'fork' mode).
  Parameters:
    `value` - the maximum time (in milliseconds) allowed before declaring the test as 'timed-out'
  See Also:
    `setFork(boolean)`, `#haltOnTimeout(boolean)`

### setMaxmemory

    public void setMaxmemory(java.lang.String max)

  Set the maximum memory to be used by all forked JVMs.
  Parameters:
    `max` - the value as defined by `-mx` or `-Xmx` in the java command line options.

### setJvm

    public void setJvm(java.lang.String value)

  Set a new VM to execute the testcase. Default is `java`. Ignored if no JVM is forked.
  Parameters:
    `value` - the new VM to use instead of `java`
  See Also:
    `setFork(boolean)`

### createJvmarg

    public Commandline.Argument createJvmarg()

  Create a new JVM argument. Ignored if no JVM is forked.
  Returns:
    create a new JVM argument so that any argument can be passed to the JVM.
  See Also:
    `setFork(boolean)`

### setDir

    public void setDir(java.io.File dir)

  The directory to invoke the VM in. Ignored if no JVM is forked.
  Parameters:
    `dir` - the directory to invoke the JVM from.
  See Also:
    `setFork(boolean)`

### addSysproperty

    public void addSysproperty(Environment.Variable sysp)

  Add a nested sysproperty element. This might be useful to tranfer Ant properties to the testcases when JVM forking is not enabled.

### createClasspath

    public Path createClasspath()

### addTest

    public void addTest(JUnitTest test)

  Add a new single testcase.
  Parameters:
    `test` - a new single testcase
  See Also:
    `JUnitTest`

### createBatchTest

    public BatchTest createBatchTest()

  Create a new set of testcases (also called ..batchtest) and add it to the list.
  Returns:
    a new instance of a batch test.
  See Also:
    `BatchTest`

### addFormatter

    public void addFormatter(FormatterElement fe)

  Add a new formatter to all tests of this task.

### execute

    public void execute()
                 throws BuildException

  Runs the testcase.
  Overrides:
    `execute` in class `Task`
  Following copied from class: `org.apache.tools.ant.Task`
  Throws:
    `BuildException` - if someting goes wrong with the build

### execute

    protected void execute(JUnitTest test)
                    throws BuildException

### createWatchdog

    protected ExecuteWatchdog createWatchdog()
                                      throws BuildException

  Returns:
    `null` if there is a timeout value, otherwise the watchdog instance.

### getDefaultOutput

    protected java.io.OutputStream getDefaultOutput()

  get the default output for a formatter.

### getIndividualTests

    protected java.util.Enumeration getIndividualTests()

  Merge all individual tests from the batchtest with all individual tests and return an enumeration over all `JUnitTest`.

### allTests

    protected java.util.Enumeration allTests()

### getOutput

    protected java.io.File getOutput(FormatterElement fe,
                                     JUnitTest test)

  return the file or null if does not use a file

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000 Apache Software Foundation. All Rights Reserved.