org.apache.tools.ant.taskdefs.optional.junit

## Class JUnitTest

- java.lang.Object
- - org.apache.tools.ant.taskdefs.optional.junit.BaseTest
  - - org.apache.tools.ant.taskdefs.optional.junit.JUnitTest

- All Implemented Interfaces:
    java.lang.Cloneable

      public class JUnitTest
      extends BaseTest
      implements java.lang.Cloneable

  Run a single JUnit test.

  The JUnit test is actually run by `JUnitTestRunner`. So read the doc comments for that class :)

  Since:
    Ant 1.2
  See Also:
    `JUnitTask`, `JUnitTestRunner`

- - ### Field Summary

    - ### Fields inherited from class org.apache.tools.ant.taskdefs.optional.junit.BaseTest

      `destDir, errorProperty, failureProperty, filtertrace, fork, formatters, haltOnError, haltOnFail, ifProperty, unlessProperty`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JUnitTest()` No arg constructor.
    `JUnitTest(java.lang.String name)` Constructor with name.
    `JUnitTest(java.lang.String name, boolean haltOnError, boolean haltOnFailure, boolean filtertrace)` Constructor with options.
    `JUnitTest(java.lang.String name, boolean haltOnError, boolean haltOnFailure, boolean filtertrace, java.lang.String[] methods)` Constructor with options.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Object` | `clone()`
    `long` | `errorCount()` Get the number of errors.
    `long` | `failureCount()` Get the number of failures.
    `FormatterElement[]` | `getFormatters()` Get the formatters set for this test.
    `java.lang.String` | `getName()` Get the name of the test class.
    `java.lang.String` | `getOutfile()` Get the name of the output file
    `java.util.Properties` | `getProperties()` Get the properties used in the test.
    `long` | `getRunTime()` Get the run time.
    `static java.lang.String[]` | `parseTestMethodNamesList(java.lang.String methodNames)` Parses a comma-separated list of method names and check their validity.
    `long` | `runCount()` Get the number of runs.
    `void` | `setCounts(long runs, long failures, long errors)` Set the number of runs, failures and errors.
    `void` | `setMethods(java.lang.String value)` Sets names of individual test methods to be executed.
    `void` | `setName(java.lang.String value)` Set the name of the test class.
    `void` | `setOutfile(java.lang.String value)` Set the name of the output file.
    `void` | `setProperties(java.util.Hashtable p)` Set the properties to be used in the test.
    `void` | `setRunTime(long runTime)` Set the runtime.
    `boolean` | `shouldRun(Project p)` Check if this test should run based on the if and unless attributes.

    - ### Methods inherited from class org.apache.tools.ant.taskdefs.optional.junit.BaseTest

      `addFormatter, getErrorProperty, getFailureProperty, getFiltertrace, getFork, getHaltonerror, getHaltonfailure, getIfCondition, getTodir, getUnlessCondition, setErrorProperty, setFailureProperty, setFiltertrace, setFork, setHaltonerror, setHaltonfailure, setIf, setIf, setTodir, setUnless, setUnless`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JUnitTest

          public JUnitTest()

      No arg constructor.

    - #### JUnitTest

          public JUnitTest(java.lang.String name)

      Constructor with name.
      Parameters:
        `name` - the name of the test.

    - #### JUnitTest

          public JUnitTest(java.lang.String name,
                   boolean haltOnError,
                   boolean haltOnFailure,
                   boolean filtertrace)

      Constructor with options.
      Parameters:
        `name` - the name of the test.
        `haltOnError` - if true halt the tests if there is an error.
        `haltOnFailure` - if true halt the tests if there is a failure.
        `filtertrace` - if true filter stack traces.

    - #### JUnitTest

          public JUnitTest(java.lang.String name,
                   boolean haltOnError,
                   boolean haltOnFailure,
                   boolean filtertrace,
                   java.lang.String[] methods)

      Constructor with options.
      Parameters:
        `name` - the name of the test.
        `haltOnError` - if true halt the tests if there is an error.
        `haltOnFailure` - if true halt the tests if there is a failure.
        `filtertrace` - if true filter stack traces.
        `methods` - if non-null run only these test methods
      Since:
        1.8.2

  - ### Method Detail

    - #### setMethods

          public void setMethods(java.lang.String value)

      Sets names of individual test methods to be executed.
      Parameters:
        `value` - comma-separated list of names of individual test methods to be executed, or `null` if all test methods should be executed
      Since:
        1.8.2

    - #### setName

          public void setName(java.lang.String value)

      Set the name of the test class.
      Parameters:
        `value` - the name to use.

    - #### setOutfile

          public void setOutfile(java.lang.String value)

      Set the name of the output file.
      Parameters:
        `value` - the name of the output file to use.

    - #### parseTestMethodNamesList

          public static java.lang.String[] parseTestMethodNamesList(java.lang.String methodNames)
                                                             throws java.lang.IllegalArgumentException

      Parses a comma-separated list of method names and check their validity.
      Parameters:
        `methodNames` - comma-separated list of method names to be parsed
      Returns:
        array of individual test method names
      Throws:
        `java.lang.IllegalArgumentException` - if the given string is `null` or if it is not a comma-separated list of valid Java identifiers; an empty string is acceptable and is handled as an empty list
      Since:
        1.8.2

    - #### getName

          public java.lang.String getName()

      Get the name of the test class.
      Returns:
        the name of the test.

    - #### getOutfile

          public java.lang.String getOutfile()

      Get the name of the output file
      Returns:
        the name of the output file.

    - #### setCounts

          public void setCounts(long runs,
                       long failures,
                       long errors)

      Set the number of runs, failures and errors.
      Parameters:
        `runs` - the number of runs.
        `failures` - the number of failures.
        `errors` - the number of errors.

    - #### setRunTime

          public void setRunTime(long runTime)

      Set the runtime.
      Parameters:
        `runTime` - the time in milliseconds.

    - #### runCount

          public long runCount()

      Get the number of runs.
      Returns:
        the number of runs.

    - #### failureCount

          public long failureCount()

      Get the number of failures.
      Returns:
        the number of failures.

    - #### errorCount

          public long errorCount()

      Get the number of errors.
      Returns:
        the number of errors.

    - #### getRunTime

          public long getRunTime()

      Get the run time.
      Returns:
        the run time in milliseconds.

    - #### getProperties

          public java.util.Properties getProperties()

      Get the properties used in the test.
      Returns:
        the properties.

    - #### setProperties

          public void setProperties(java.util.Hashtable p)

      Set the properties to be used in the test.
      Parameters:
        `p` - the properties. This is a copy of the projects ant properties.

    - #### shouldRun

          public boolean shouldRun(Project p)

      Check if this test should run based on the if and unless attributes.
      Parameters:
        `p` - the project to use to check if the if and unless properties exist in.
      Returns:
        true if this test or testsuite should be run.

    - #### getFormatters

          public FormatterElement[] getFormatters()

      Get the formatters set for this test.
      Returns:
        the formatters as an array.

    - #### clone

          public java.lang.Object clone()

      Overrides:
        `clone` in class `java.lang.Object`
      Returns:
        a clone of this test.
      Since:
        Ant 1.5