| API Documentation: | Test |
|---|
Executes tests. Supports JUnit (3.8.x or 4.x) or TestNG tests.
An example with a blend of various settings
apply plugin: 'java' //so that 'test' task is added test { //configuring a system property for tests systemProperty 'some.prop', 'value' //tuning the included/excluded tests include 'org/foo/**' exclude 'org/boo/**' //makes the standard streams (err and out) visible at console when running tests testLogging.showStandardStreams = true //tweaking memory settings for the forked vm that runs tests jvmArgs '-Xms128m', '-Xmx512m', '-XX:MaxPermSize=128m' //listening to test execution events beforeTest { descriptor -> logger.lifecycle("Running test: " + descriptor) } onOutput { descriptor, event -> logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message ) } }
| Property | Description |
allJvmArgs | The full set of arguments to use to launch the JVM for the process. This includes arguments to define system properties, the maximum heap size, and the bootstrap classpath. |
bootstrapClasspath | The bootstrap classpath to use for the process. The default bootstrap classpath for the JVM is used when this classpath is empty. |
classpath | The classpath to use to execute the tests. |
debug | Returns true if debugging is enabled for the process. When enabled, the process is started suspended and listening on port 5005. |
enableAssertions | Returns true if assertions are enabled for the process. |
environment | The environment variables to use for the process. Defaults to the environment of this process. |
excludes | The exclude patterns for test execution. |
executable | The name of the executable to use. |
forkEvery | 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). |
ignoreFailures | Specifies whether the build should break when the verifications performed by this task fail. |
includes | The include patterns for test execution. |
jvmArgs | The extra arguments to use to launch the JVM for the process. Does not include system properties and the maximum heap size. |
maxHeapSize | The maximum heap size for the process, if any. |
maxParallelForks | The maximum number of forked test processes to execute in parallel. The default value is 1 (no parallel test execution). |
options | The test options options. |
scanForTestClasses | Specifies whether test classes should be detected. When |
systemProperties | The system properties which will be used for the process. |
testClassesDir | The root folder for the compiled test sources. |
testLogging | Allows configuring the logging of the test execution, for example log eagerly the standard output, etc. |
testReport | Specifies whether the test report should be generated. |
testReportDir | The root folder for the test reports. |
testResultsDir | The root folder for the test results. |
testSrcDirs | The directories containing the test source. |
workingDir | The working directory for the process. Defaults to the project directory. |
The full set of arguments to use to launch the JVM for the process. This includes arguments to define system properties, the maximum heap size, and the bootstrap classpath.
FileCollection bootstrapClasspath
The bootstrap classpath to use for the process. The default bootstrap classpath for the JVM is used when this classpath is empty.
- Default with
javaplugin: []
FileCollection classpath
The classpath to use to execute the tests.
- Default with
javaplugin: project.sourceSets.test.runtimeClasspath
Returns true if debugging is enabled for the process. When enabled, the process is started suspended and listening on port 5005.
- Default with
javaplugin: false
Returns true if assertions are enabled for the process.
- Default with
javaplugin: true
The environment variables to use for the process. Defaults to the environment of this process.
- Default with
javaplugin: - environment of the current process
String executable
The name of the executable to use.
- Default with
javaplugin: - java command for the current JVM.
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).
- Default with
javaplugin: 0
Specifies whether the build should break when the verifications performed by this task fail.
- Default with
javaplugin: false
The extra arguments to use to launch the JVM for the process. Does not include system properties and the maximum heap size.
- Default with
javaplugin: []
The maximum number of forked test processes to execute in parallel. The default value is 1 (no parallel test execution).
- Default with
javaplugin: 1
TestFrameworkOptions options (read-only)
The test options options.
Be sure to call the appropriate Test.useJUnit() or Test.useTestNG() method before using this method.
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.
- Default with
javaplugin: true
The system properties which will be used for the process.
- Default with
javaplugin: [:]
File testClassesDir
The root folder for the compiled test sources.
- Default with
javaplugin: project.sourceSets.test.classesDir
TestLogging testLogging (read-only)
Allows configuring the logging of the test execution, for example log eagerly the standard output, etc.
apply plugin: 'java' //makes the standard streams (err and out) visible at console when running tests test.testLogging.showStandardStreams = true
Specifies whether the test report should be generated.
- Default with
javaplugin: true
File testReportDir
The root folder for the test reports.
- Default with
javaplugin: project.testReportDir
File testResultsDir
The root folder for the test results.
- Default with
javaplugin: project.testResultsDir
The directories containing the test source.
- Default with
javaplugin: project.sourceSets.test.java.srcDirs
File workingDir
The working directory for the process. Defaults to the project directory.
- Default with
javaplugin: project.projectDir
| Block | Description |
testLogging | Allows configuring the logging of the test execution, for example log eagerly the standard output, etc. |
Allows configuring the logging of the test execution, for example log eagerly the standard output, etc.
apply plugin: 'java' //makes the standard streams (err and out) visible at console when running tests test.testLogging { showStandardStreams = true }
- Delegates to:
TestLoggingfromtestLogging
| Method | Description |
addTestListener(listener) | Registers a test listener with this task. Consider also the following handy methods for quicker hooking into test execution:
|
addTestOutputListener(listener) | Registers a output listener with this task. Quicker way of hooking into output events is using the |
afterSuite(closure) | Adds a closure to be notified after a test suite has executed. A |
afterTest(closure) | Adds a closure to be notified after a test has executed. A |
beforeSuite(closure) | Adds a closure to be notified before a test suite is executed. A |
beforeTest(closure) | Adds a closure to be notified before a test is executed. A |
bootstrapClasspath(classpath) | Adds the given values to the end of the bootstrap classpath for the process. |
copyTo(target) | Copies these options to the given options. |
copyTo(target) | Copies these options to the given target options. |
environment(name, value) | Adds an environment variable to the environment for this process. |
environment(environmentVariables) | Adds some environment variables to the environment for this process. |
exclude(excludeSpec) | Adds an exclude spec. This method may be called multiple times to append new specs.The given closure is passed a
|
exclude(excludes) | Adds exclude patterns for the files in the test classes directory (e.g. '**null*Test.class')). |
exclude(excludes) | Adds exclude patterns for the files in the test classes directory (e.g. '**null*Test.class')). |
exclude(excludeSpec) | Adds an exclude spec. This method may be called multiple times to append new specs. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed. |
executable(executable) | Sets the name of the executable to use. |
include(includeSpec) | Adds an include spec. This method may be called multiple times to append new specs. The given closure is passed a
|
include(includes) | Adds include patterns for the files in the test classes directory (e.g. '**null*Test.class')). |
include(includes) | Adds include patterns for the files in the test classes directory (e.g. '**null*Test.class')). |
include(includeSpec) | Adds an include spec. This method may be called multiple times to append new specs. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns or specs to be included. |
jvmArgs(arguments) | Adds some arguments to use to launch the JVM for the process. |
jvmArgs(arguments) | Adds some arguments to use to launch the JVM for the process. |
onOutput(closure) | Adds a closure to be notified when output from the test received.
A |
removeTestListener(listener) | Unregisters a test listener with this task. This method will only remove listeners that were added by calling
|
removeTestOutputListener(listener) | Unregisters a test output listener with this task. This method will only remove listeners that were added by calling
|
systemProperties(properties) | Adds some system properties to use for the process. |
useJUnit() | Specifies that JUnit should be used to execute the tests. |
useJUnit(testFrameworkConfigure) | Specifies that JUnit should be used to execute the tests. |
useTestNG() | Specifies that TestNG should be used to execute the tests. |
useTestNG(testFrameworkConfigure) | Specifies that TestNG should be used to execute the tests. |
workingDir(dir) | Sets the working directory for the process. The supplied argument is evaluated as for |
void addTestListener(TestListener listener)
Registers a test listener with this task. Consider also the following handy methods for quicker hooking into test execution:
Test.beforeTest(), Test.afterTest(),
Test.beforeSuite(), Test.afterSuite()
This listener will NOT be notified of tests executed by other tasks.
To get that behavior, use Gradle.addListener().
void addTestOutputListener(TestOutputListener listener)
Registers a output listener with this task. Quicker way of hooking into output events is using the Test.onOutput() method.
void afterSuite(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.
void afterTest(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.
void beforeSuite(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.
void beforeTest(Closure closure)
Adds a closure to be notified before a test is executed. A TestDescriptor
instance is passed to the closure as a parameter.
Adds the given values to the end of the bootstrap classpath for the process.
Test copyTo(JavaForkOptions target)
Copies these options to the given options.
Test copyTo(ProcessForkOptions target)
Copies these options to the given target options.
Adds an environment variable to the environment for this process.
Adds some environment variables to the environment for this process.
Adds an exclude spec. This method may be called multiple times to append new specs.The given closure is passed a
FileTreeElement as its parameter.
If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match
any exclude pattern to be processed.
Adds exclude patterns for the files in the test classes directory (e.g. '**null*Test.class')).
Adds exclude patterns for the files in the test classes directory (e.g. '**null*Test.class')).
Test exclude(Spec<FileTreeElement> excludeSpec)
Spec<FileTreeElement>Adds an exclude spec. This method may be called multiple times to append new specs. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.
Adds an include spec. This method may be called multiple times to append new specs. The given closure is passed a
FileTreeElement as its parameter.
If includes are not provided, then all files in this container will be included. If includes are provided, then a
file must match at least one of the include patterns or specs to be included.
Adds include patterns for the files in the test classes directory (e.g. '**null*Test.class')).
Adds include patterns for the files in the test classes directory (e.g. '**null*Test.class')).
Test include(Spec<FileTreeElement> includeSpec)
Spec<FileTreeElement>Adds an include spec. This method may be called multiple times to append new specs. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns or specs to be included.
void onOutput(Closure closure)
Adds a closure to be notified when output from the test received.
A TestDescriptor
and TestOutputEvent instance are passed to the closure as a parameter.
apply plugin: 'java' test { onOutput { descriptor, event -> if (event.destination == TestOutputEvent.Destination.StdErr) { logger.error("Test: " + descriptor + ", error: " + event.message) } } }
void removeTestListener(TestListener listener)
Unregisters a test listener with this task. This method will only remove listeners that were added by calling
Test.addTestListener() on this task. If the listener was registered
with Gradle using Gradle.addListener() this method will not do anything.
Instead, use Gradle.removeListener().
void removeTestOutputListener(TestOutputListener listener)
Unregisters a test output listener with this task. This method will only remove listeners that were added by calling
Test.addTestOutputListener() on this task. If the listener was registered
with Gradle using Gradle.addListener() this method will not do anything.
Instead, use Gradle.removeListener().
void useJUnit(Closure testFrameworkConfigure)
Specifies that JUnit should be used to execute the tests.
void useTestNG(Closure testFrameworkConfigure)
Specifies that TestNG should be used to execute the tests.
Sets the working directory for the process. The supplied argument is evaluated as for Project.file().