Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.gradle.api.tasks.testing
[Java] Class Test

    java.lang.Object
      org.gradle.api.internal.ConventionTask
          org.gradle.api.tasks.testing.Test

All Implemented Interfaces:
  JavaForkOptions, PatternFilterable, VerificationTask

    public class Test
    extends ConventionTask

Executes tests. Supports JUnit (3.8.x or 4.x) or TestNG tests.

Authors:
  Hans Dockter

Constructor Summary
`Test()`

Method Summary
`void` | `addTestListener(TestListener listener)` Registers a test listener with this task.
`void` | `afterSuite(groovy.lang.Closure closure)` Adds a closure to be notified after a test suite has executed.
`void` | `afterTest(groovy.lang.Closure closure)` Adds a closure to be notified after a test has executed.
`void` | `beforeSuite(groovy.lang.Closure closure)` Adds a closure to be notified before a test suite is executed.
`void` | `beforeTest(groovy.lang.Closure closure)` Adds a closure to be notified before a test is executed.
`Test` | `bootstrapClasspath(java.lang.Object classpath)` {@inheritDoc}
`Test` | `copyTo(ProcessForkOptions target)` {@inheritDoc}
`Test` | `copyTo(JavaForkOptions target)` {@inheritDoc}
`void` | `disableTestReport()`
`void` | `enableTestReport()`
`Test` | `environment(java.util.Map environmentVariables)` {@inheritDoc}
`Test` | `environment(java.lang.String name, java.lang.Object value)` {@inheritDoc}
`Test` | `exclude(java.lang.String excludes)` Adds exclude patterns for the files in the test classes directory (e.g. '**F;*Test.class')).
`Test` | `exclude(java.lang.Iterable excludes)` Adds exclude patterns for the files in the test classes directory (e.g. '**F;*Test.class')).
`Test` | `exclude(Spec excludeSpec)`
`Test` | `exclude(groovy.lang.Closure excludeSpec)`
`Test` | `executable(java.lang.Object executable)` {@inheritDoc}
`void` | `executeTests()`
`java.util.List` | `getAllJvmArgs()` {@inheritDoc}
`FileCollection` | `getBootstrapClasspath()` {@inheritDoc}
`FileTree` | `getCandidateClassFiles()` Returns the classes files to scan for test classes.
`FileCollection` | `getClasspath()` Returns the classpath to use to execute the tests.
`boolean` | `getDebug()` {@inheritDoc}
`boolean` | `getEnableAssertions()` {@inheritDoc}
`java.util.Map` | `getEnvironment()` {@inheritDoc}
`java.util.Set` | `getExcludes()` Returns the exclude patterns for test execution.
`java.lang.String` | `getExecutable()` {@inheritDoc}
`long` | `getForkEvery()` Returns the maximum number of test classes to execute in a forked test process.
`java.util.Set` | `getIncludes()` Returns the include patterns for test execution.
`java.util.List` | `getJvmArgs()` {@inheritDoc}
`java.lang.String` | `getMaxHeapSize()` {@inheritDoc}
`int` | `getMaxParallelForks()` Returns the maximum number of forked test processes to execute in parallel.
`TestFrameworkOptions` | `getOptions()` Returns the test options options.
`java.util.Map` | `getSystemProperties()` {@inheritDoc}
`java.io.File` | `getTestClassesDir()` Returns the root folder for the compiled test sources.
`TestFramework` | `getTestFramework()`
`java.io.File` | `getTestReportDir()` Returns the root folder for the test reports.
`java.io.File` | `getTestResultsDir()` Returns the root folder for the test results.
`java.util.List` | `getTestSrcDirs()` Returns the directories containing the test source.
`java.io.File` | `getWorkingDir()` {@inheritDoc}
`Test` | `include(java.lang.String includes)` Adds include patterns for the files in the test classes directory (e.g. '**F;*Test.class')).
`Test` | `include(java.lang.Iterable includes)` Adds include patterns for the files in the test classes directory (e.g. '**F;*Test.class')).
`Test` | `include(Spec includeSpec)`
`Test` | `include(groovy.lang.Closure includeSpec)`
`boolean` | `isIgnoreFailures()` {@inheritDoc}
`boolean` | `isScanForTestClasses()` Specifies whether test classes should be detected.
`boolean` | `isTestReport()` Specifies whether the test report should be generated.
`Test` | `jvmArgs(java.lang.Iterable arguments)` {@inheritDoc}
`Test` | `jvmArgs(java.lang.Object arguments)` {@inheritDoc}
`TestFrameworkOptions` | `options(groovy.lang.Closure testFrameworkConfigure)`
`void` | `removeTestListener(TestListener listener)` Unregisters a test listener with this task.
`void` | `setAllJvmArgs(java.lang.Iterable arguments)` {@inheritDoc}
`void` | `setBootstrapClasspath(FileCollection classpath)` {@inheritDoc}
`void` | `setClasspath(FileCollection classpath)`
`void` | `setDebug(boolean enabled)` {@inheritDoc}
`void` | `setEnableAssertions(boolean enabled)` {@inheritDoc}
`void` | `setEnvironment(java.util.Map environmentVariables)` {@inheritDoc}
`Test` | `setExcludes(java.lang.Iterable excludes)` Sets the exclude patterns for test execution.
`void` | `setExecutable(java.lang.Object executable)` {@inheritDoc}
`void` | `setForkEvery(java.lang.Long forkEvery)` Sets the maximum number of test classes to execute in a forked test process.
`Test` | `setIgnoreFailures(boolean ignoreFailures)` {@inheritDoc}
`Test` | `setIncludes(java.lang.Iterable includes)` Sets the include patterns for test execution.
`void` | `setJvmArgs(java.lang.Iterable arguments)` {@inheritDoc}
`void` | `setMaxHeapSize(java.lang.String heapSize)` {@inheritDoc}
`void` | `setMaxParallelForks(int maxParallelForks)` Sets the maximum number of forked test processes to execute in parallel.
`void` | `setScanForTestClasses(boolean scanForTestClasses)`
`void` | `setSystemProperties(java.util.Map properties)` {@inheritDoc}
`void` | `setTestClassesDir(java.io.File testClassesDir)` Sets the root folder for the compiled test sources.
`void` | `setTestReport(boolean testReport)`
`void` | `setTestReportDir(java.io.File testReportDir)` Sets the root folder for the test reports.
`void` | `setTestResultsDir(java.io.File testResultsDir)` Sets the root folder for the test results.
`void` | `setTestSrcDirs(java.util.List testSrcDir)`
`void` | `setWorkingDir(java.lang.Object dir)` {@inheritDoc}
`Test` | `systemProperties(java.util.Map properties)` {@inheritDoc}
`Test` | `systemProperty(java.lang.String name, java.lang.Object value)` {@inheritDoc}
`TestFramework` | `testFramework(groovy.lang.Closure testFrameworkConfigure)`
`void` | `useJUnit()` Specifies that JUnit should be used to execute the tests.
`void` | `useJUnit(groovy.lang.Closure testFrameworkConfigure)` Specifies that JUnit should be used to execute the tests.
`void` | `useTestNG()` Specifies that TestNG should be used to execute the tests.
`void` | `useTestNG(groovy.lang.Closure testFrameworkConfigure)` Specifies that TestNG should be used to execute the tests.
`Test` | `workingDir(java.lang.Object dir)` {@inheritDoc}

Constructor Detail

### Test

    public Test()

Method Detail

### addTestListener

    public void addTestListener(TestListener listener)

  Registers a test listener with this task. This listener will NOT be notified of tests executed by other tasks. To get that behavior, use Gradle.addListener.
  Parameters:
    `listener` - The listener to add.

### afterSuite

    public void afterSuite(groovy.lang.Closure closure)

  Adds a closure to be notified after a test suite has executed. A TestDescriptor and TestResult instance are passed to the closure as a parameter.

  This method is also called after all test suites are executed. The provided descriptor will have a null parent suite.

  Parameters:
    `closure` - The closure to call.

### afterTest

    public void afterTest(groovy.lang.Closure closure)

  Adds a closure to be notified after a test has executed. A TestDescriptor and TestResult instance are passed to the closure as a parameter.
  Parameters:
    `closure` - The closure to call.

### beforeSuite

    public void beforeSuite(groovy.lang.Closure closure)

  Adds a closure to be notified before a test suite is executed. A TestDescriptor instance is passed to the closure as a parameter.

  This method is also called before any test suites are executed. The provided descriptor will have a null parent suite.

  Parameters:
    `closure` - The closure to call.

### beforeTest

    public void beforeTest(groovy.lang.Closure closure)

  Adds a closure to be notified before a test is executed. A TestDescriptor instance is passed to the closure as a parameter.
  Parameters:
    `closure` - The closure to call.

### bootstrapClasspath

    public Test bootstrapClasspath(java.lang.Object classpath)

  {@inheritDoc}

### copyTo

    public Test copyTo(ProcessForkOptions target)

  {@inheritDoc}

### copyTo

    public Test copyTo(JavaForkOptions target)

  {@inheritDoc}

### disableTestReport

    public void disableTestReport()

### enableTestReport

    public void enableTestReport()

### environment

    public Test environment(java.util.Map environmentVariables)

  {@inheritDoc}

### environment

    public Test environment(java.lang.String name, java.lang.Object value)

  {@inheritDoc}

### exclude

    public Test exclude(java.lang.String excludes)

  Adds exclude patterns for the files in the test classes directory (e.g. '**F;*Test.class')).
  See Also:
    setExcludes(Iterable)

### exclude

    public Test exclude(java.lang.Iterable excludes)

  Adds exclude patterns for the files in the test classes directory (e.g. '**F;*Test.class')).
  See Also:
    setExcludes(Iterable)

### exclude

    public Test exclude(Spec excludeSpec)

### exclude

    public Test exclude(groovy.lang.Closure excludeSpec)

### executable

    public Test executable(java.lang.Object executable)

  {@inheritDoc}

### executeTests

    @TaskAction
    public void executeTests()

### getAllJvmArgs

    public java.util.List getAllJvmArgs()

  {@inheritDoc}

### getBootstrapClasspath

    public FileCollection getBootstrapClasspath()

  {@inheritDoc}

### getCandidateClassFiles

    @InputFiles
    @Input // Also marked as input to force tests to run when the set of candidate class files changes
    public FileTree getCandidateClassFiles()

  Returns the classes files to scan for test classes.
  Returns:
    The candidate class files.

### getClasspath

    @InputFiles
    public FileCollection getClasspath()

  Returns the classpath to use to execute the tests.

### getDebug

    public boolean getDebug()

  {@inheritDoc}

### getEnableAssertions

    public boolean getEnableAssertions()

  {@inheritDoc}

### getEnvironment

    public java.util.Map getEnvironment()

  {@inheritDoc}

### getExcludes

    public java.util.Set getExcludes()

  Returns the exclude patterns for test execution.
  See Also:
    exclude(String...)

### getExecutable

    public java.lang.String getExecutable()

  {@inheritDoc}

### getForkEvery

    public long getForkEvery()

  Returns the maximum number of test classes to execute in a forked test process. The forked test process will be restarted when this limit is reached. The default value is 0 (no maximum).
  Returns:
    The maximum number of test classes. Returns 0 when there is no maximum.

### getIncludes

    public java.util.Set getIncludes()

  Returns the include patterns for test execution.
  See Also:
    include(String...)

### getJvmArgs

    public java.util.List getJvmArgs()

  {@inheritDoc}

### getMaxHeapSize

    public java.lang.String getMaxHeapSize()

  {@inheritDoc}

### getMaxParallelForks

    public int getMaxParallelForks()

  Returns the maximum number of forked test processes to execute in parallel. The default value is 1 (no parallel test execution).
  Returns:
    The maximum number of forked test processes.

### getOptions

    @Nested
    public TestFrameworkOptions getOptions()

  Returns the test options options.

  Be sure to call the appropriate useJUnit() or useTestNG() method before using this method.

  Returns:
    The testframework options.

### getSystemProperties

    public java.util.Map getSystemProperties()

  {@inheritDoc}

### getTestClassesDir

    public java.io.File getTestClassesDir()

  Returns the root folder for the compiled test sources.
  Returns:
    All test class directories to be used.

### getTestFramework

    public TestFramework getTestFramework()

### getTestReportDir

    @OutputDirectory
    public java.io.File getTestReportDir()

  Returns the root folder for the test reports.
  Returns:
    the test report directory, containing the test report mostly in HTML form.

### getTestResultsDir

    @OutputDirectory
    public java.io.File getTestResultsDir()

  Returns the root folder for the test results.
  Returns:
    the test result directory, containing the internal test results, mostly in xml form.

### getTestSrcDirs

    @InputFiles
    public java.util.List getTestSrcDirs()

  Returns the directories containing the test source.

### getWorkingDir

    public java.io.File getWorkingDir()

  {@inheritDoc}

### include

    public Test include(java.lang.String includes)

  Adds include patterns for the files in the test classes directory (e.g. '**F;*Test.class')).
  See Also:
    setIncludes(Iterable)

### include

    public Test include(java.lang.Iterable includes)

  Adds include patterns for the files in the test classes directory (e.g. '**F;*Test.class')).
  See Also:
    setIncludes(Iterable)

### include

    public Test include(Spec includeSpec)

### include

    public Test include(groovy.lang.Closure includeSpec)

### isIgnoreFailures

    public boolean isIgnoreFailures()

  {@inheritDoc}

### isScanForTestClasses

    public boolean isScanForTestClasses()

  Specifies whether test classes should be detected. When `true` the classes which match the include and exclude patterns are scanned for test classes, and any found are executed. When `false` the classes which match the include and exclude patterns are executed.

### isTestReport

    public boolean isTestReport()

  Specifies whether the test report should be generated.

### jvmArgs

    public Test jvmArgs(java.lang.Iterable arguments)

  {@inheritDoc}

### jvmArgs

    public Test jvmArgs(java.lang.Object arguments)

  {@inheritDoc}

### options

    public TestFrameworkOptions options(groovy.lang.Closure testFrameworkConfigure)

### removeTestListener

    public void removeTestListener(TestListener listener)

  Unregisters a test listener with this task. This method will only remove listeners that were added by calling addTestListener(org.gradle.api.tasks.testing.TestListener) on this task. If the listener was registered with Gradle using Gradle.addListener this method will not do anything. Instead, use Gradle.removeListener.
  Parameters:
    `listener` - The listener to remove.

### setAllJvmArgs

    public void setAllJvmArgs(java.lang.Iterable arguments)

  {@inheritDoc}

### setBootstrapClasspath

    public void setBootstrapClasspath(FileCollection classpath)

  {@inheritDoc}

### setClasspath

    public void setClasspath(FileCollection classpath)

### setDebug

    public void setDebug(boolean enabled)

  {@inheritDoc}

### setEnableAssertions

    public void setEnableAssertions(boolean enabled)

  {@inheritDoc}

### setEnvironment

    public void setEnvironment(java.util.Map environmentVariables)

  {@inheritDoc}

### setExcludes

    public Test setExcludes(java.lang.Iterable excludes)

  Sets the exclude patterns for test execution.
  Parameters:
    `excludes` - The patterns list
  See Also:
    exclude(String...)

### setExecutable

    public void setExecutable(java.lang.Object executable)

  {@inheritDoc}

### setForkEvery

    public void setForkEvery(java.lang.Long forkEvery)

  Sets the maximum number of test classes to execute in a forked test process. Use null or 0 to use no maximum.
  Parameters:
    `forkEvery` - The maximum number of test classes. Use null or 0 to specify no maximum.

### setIgnoreFailures

    public Test setIgnoreFailures(boolean ignoreFailures)

  {@inheritDoc}

### setIncludes

    public Test setIncludes(java.lang.Iterable includes)

  Sets the include patterns for test execution.
  Parameters:
    `includes` - The patterns list
  See Also:
    include(String...)

### setJvmArgs

    public void setJvmArgs(java.lang.Iterable arguments)

  {@inheritDoc}

### setMaxHeapSize

    public void setMaxHeapSize(java.lang.String heapSize)

  {@inheritDoc}

### setMaxParallelForks

    public void setMaxParallelForks(int maxParallelForks)

  Sets the maximum number of forked test processes to execute in parallel. Set to 1 to disable parallel test execution.
  Parameters:
    `maxParallelForks` - The maximum number of forked test processes.

### setScanForTestClasses

    public void setScanForTestClasses(boolean scanForTestClasses)

### setSystemProperties

    public void setSystemProperties(java.util.Map properties)

  {@inheritDoc}

### setTestClassesDir

    public void setTestClassesDir(java.io.File testClassesDir)

  Sets the root folder for the compiled test sources.
  Parameters:
    `testClassesDir` - The root folder

### setTestReport

    public void setTestReport(boolean testReport)

### setTestReportDir

    public void setTestReportDir(java.io.File testReportDir)

  Sets the root folder for the test reports.
  Parameters:
    `testReportDir` - The root folder

### setTestResultsDir

    public void setTestResultsDir(java.io.File testResultsDir)

  Sets the root folder for the test results.
  Parameters:
    `testResultsDir` - The root folder

### setTestSrcDirs

    public void setTestSrcDirs(java.util.List testSrcDir)

### setWorkingDir

    public void setWorkingDir(java.lang.Object dir)

  {@inheritDoc}

### systemProperties

    public Test systemProperties(java.util.Map properties)

  {@inheritDoc}

### systemProperty

    public Test systemProperty(java.lang.String name, java.lang.Object value)

  {@inheritDoc}

### testFramework

    public TestFramework testFramework(groovy.lang.Closure testFrameworkConfigure)

### useJUnit

    public void useJUnit()

  Specifies that JUnit should be used to execute the tests.

### useJUnit

    public void useJUnit(groovy.lang.Closure testFrameworkConfigure)

  Specifies that JUnit should be used to execute the tests.
  Parameters:
    `testFrameworkConfigure` - A closure used to configure the JUint options. This closure is passed an instance of type JUnitOptions.

### useTestNG

    public void useTestNG()

  Specifies that TestNG should be used to execute the tests.

### useTestNG

    public void useTestNG(groovy.lang.Closure testFrameworkConfigure)

  Specifies that TestNG should be used to execute the tests.
  Parameters:
    `testFrameworkConfigure` - A closure used to configure the JUint options. This closure is passed an instance of type JUnitOptions.

### workingDir

    public Test workingDir(java.lang.Object dir)

  {@inheritDoc}

Groovy Documentation