@CacheableTask public class Test extends AbstractTestTask implements JavaForkOptions, PatternFilterable
apply plugin: 'java' // adds 'test' task
test {
// enable TestNG support (default is JUnit)
useTestNG()
// set a system property for the test JVM(s)
systemProperty 'some.prop', 'value'
// explicitly include or exclude tests
include 'org/foo/**'
exclude 'org/boo/**'
// show standard out and standard error of the test JVM(s) on the console
testLogging.showStandardStreams = true
// set heap size for the test JVM(s)
minHeapSize = "128m"
maxHeapSize = "512m"
// set JVM arguments for the test JVM(s)
jvmArgs '-XX:MaxPermSize=256m'
// listen to events in the test execution lifecycle
beforeTest { descriptor ->
logger.lifecycle("Running test: " + descriptor)
}
// listen to standard out and standard error of the test JVM(s)
onOutput { descriptor, event ->
logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
}
}
The test process can be started in debug mode (see getDebug()) in an ad-hoc manner by supplying the `--debug-jvm` switch when invoking the build.
gradle someTestTask --debug-jvm
Task.NamerTASK_ACTION, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE| Constructor and Description |
|---|
Test() |
| Modifier and Type | Method and Description |
|---|---|
Test |
bootstrapClasspath(Object... classpath)
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.
|
protected org.gradle.api.internal.tasks.testing.TestExecuter<org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec> |
createTestExecuter()
Creates test executer.
|
protected org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec |
createTestExecutionSpec()
Creates test execution specification.
|
Test |
environment(Map<String,?> environmentVariables)
Adds some environment variables to the environment for this process.
|
Test |
environment(String name,
Object value)
Adds an environment variable to the environment for this process.
|
Test |
exclude(Closure excludeSpec)
Adds an exclude spec.
|
Test |
exclude(Iterable<String> excludes)
Adds exclude patterns for the files in the test classes directory (e.g.
|
Test |
exclude(Spec<FileTreeElement> excludeSpec)
Adds an exclude spec.
|
Test |
exclude(String... excludes)
Adds exclude patterns for the files in the test classes directory (e.g.
|
Test |
executable(Object executable)
Sets the name of the executable to use.
|
void |
executeTests() |
void |
filter(Action<TestFilter> action)
Executes the action against the
AbstractTestTask.getFilter(). |
protected org.gradle.internal.actor.ActorFactory |
getActorFactory() |
List<String> |
getAllJvmArgs()
Returns the full set of arguments to use to launch the JVM for the process.
|
FileCollection |
getBootstrapClasspath()
Returns the bootstrap classpath to use for the process.
|
FileTree |
getCandidateClassFiles()
Returns the classes files to scan for test classes.
|
protected org.gradle.api.internal.initialization.loadercache.ClassLoaderCache |
getClassLoaderCache() |
FileCollection |
getClasspath()
Returns the classpath to use to execute the tests.
|
boolean |
getDebug()
Returns true if debugging is enabled for the process.
|
String |
getDefaultCharacterEncoding()
Returns the default character encoding to use.
|
boolean |
getEnableAssertions()
Returns true if assertions are enabled for the process.
|
Map<String,Object> |
getEnvironment()
The environment variables to use for the process.
|
Set<String> |
getExcludes()
Returns the exclude patterns for test execution.
|
String |
getExecutable()
Returns the name of the executable to use.
|
protected org.gradle.api.internal.file.FileResolver |
getFileResolver() |
long |
getForkEvery()
Returns the maximum number of test classes to execute in a forked test process.
|
Set<String> |
getIncludes()
Returns the include patterns for test execution.
|
JavaVersion |
getJavaVersion()
Returns the version of Java used to run the tests based on the executable specified by
getExecutable(). |
List<String> |
getJvmArgs()
Returns the extra arguments to use to launch the JVM for the process.
|
String |
getMaxHeapSize()
Returns the maximum heap size for the process, if any.
|
int |
getMaxParallelForks()
Returns the maximum number of forked test processes to execute in parallel.
|
String |
getMinHeapSize()
Returns the minimum heap size for the process, if any.
|
protected org.gradle.api.internal.classpath.ModuleRegistry |
getModuleRegistry() |
protected List<String> |
getNoMatchingTestErrorReasons()
Returns the reasons for no matching test error.
|
TestFrameworkOptions |
getOptions()
Returns test framework specific options.
|
protected org.gradle.process.internal.worker.WorkerProcessFactory |
getProcessBuilderFactory() |
Map<String,Object> |
getSystemProperties()
Returns the system properties which will be used for the process.
|
File |
getTestClassesDir()
Deprecated.
Use
getTestClassesDirs(). |
FileCollection |
getTestClassesDirs()
Returns the directories for the compiled test sources.
|
org.gradle.api.internal.tasks.testing.TestFramework |
getTestFramework() |
File |
getWorkingDir()
Returns the working directory for the process.
|
Test |
include(Closure includeSpec)
Adds an include spec.
|
Test |
include(Iterable<String> includes)
Adds include patterns for the files in the test classes directory (e.g.
|
Test |
include(Spec<FileTreeElement> includeSpec)
Adds an include spec.
|
Test |
include(String... includes)
Adds include patterns for the files in the test classes directory (e.g.
|
boolean |
isScanForTestClasses()
Specifies whether test classes should be detected.
|
Test |
jvmArgs(Iterable<?> arguments)
Adds some arguments to use to launch the JVM for the process.
|
Test |
jvmArgs(Object... arguments)
Adds some arguments to use to launch the JVM for the process.
|
TestFrameworkOptions |
options(Action<? super TestFrameworkOptions> testFrameworkConfigure)
Configures test framework specific options.
|
TestFrameworkOptions |
options(Closure testFrameworkConfigure)
Configures test framework specific options.
|
void |
setAllJvmArgs(Iterable<?> arguments)
Sets the full set of arguments to use to launch the JVM for the process.
|
void |
setAllJvmArgs(List<String> arguments)
Sets the full set of arguments to use to launch the JVM for the process.
|
void |
setBootstrapClasspath(FileCollection classpath)
Sets the bootstrap classpath to use for the process.
|
void |
setClasspath(FileCollection classpath) |
void |
setDebug(boolean enabled)
Enable or disable debugging for the process.
|
void |
setDefaultCharacterEncoding(String defaultCharacterEncoding)
Sets the default character encoding to use.
|
void |
setEnableAssertions(boolean enabled)
Enable or disable assertions for the process.
|
void |
setEnvironment(Map<String,?> environmentVariables)
Sets the environment variable to use for the process.
|
Test |
setExcludes(Iterable<String> excludes)
Sets the exclude patterns for test execution.
|
void |
setExecutable(Object executable)
Sets the name of the executable to use.
|
void |
setExecutable(String executable)
Sets the name of the executable to use.
|
void |
setForkEvery(Long forkEvery)
Sets the maximum number of test classes to execute in a forked test process.
|
Test |
setIncludes(Iterable<String> includes)
Sets the include patterns for test execution.
|
void |
setJvmArgs(Iterable<?> arguments)
Sets the extra arguments to use to launch the JVM for the process.
|
void |
setJvmArgs(List<String> arguments)
Sets the extra arguments to use to launch the JVM for the process.
|
void |
setMaxHeapSize(String heapSize)
Sets the maximum heap size for the process.
|
void |
setMaxParallelForks(int maxParallelForks)
Sets the maximum number of forked test processes to execute in parallel.
|
void |
setMinHeapSize(String heapSize)
Sets the minimum heap size for the process.
|
void |
setScanForTestClasses(boolean scanForTestClasses) |
void |
setSystemProperties(Map<String,?> properties)
Sets the system properties to use for the process.
|
void |
setTestClassesDir(File testClassesDir)
Deprecated.
|
void |
setTestClassesDirs(FileCollection testClassesDirs)
Sets the directories to scan for compiled test sources.
|
Test |
setTestNameIncludePatterns(List<String> testNamePattern)
Sets the test name patterns to be included in execution.
|
void |
setWorkingDir(File dir)
Sets the working directory for the process.
|
void |
setWorkingDir(Object dir)
Sets the working directory for the process.
|
Test |
systemProperties(Map<String,?> properties)
Adds some system properties to use for the process.
|
Test |
systemProperty(String name,
Object value)
Adds a system property to use for the process.
|
org.gradle.api.internal.tasks.testing.TestFramework |
testFramework(Closure testFrameworkConfigure) |
void |
useJUnit()
Specifies that JUnit should be used to execute the tests.
|
void |
useJUnit(Action<? super JUnitOptions> testFrameworkConfigure)
Specifies that JUnit should be used to execute the tests, configuring JUnit specific options.
|
void |
useJUnit(Closure testFrameworkConfigure)
Specifies that JUnit should be used to execute the tests, configuring JUnit specific options.
|
void |
useTestNG()
Specifies that TestNG should be used to execute the tests.
|
void |
useTestNG(Action<? super TestFrameworkOptions> testFrameworkConfigure)
Specifies that TestNG should be used to execute the tests, configuring TestNG specific options.
|
void |
useTestNG(Closure testFrameworkConfigure)
Specifies that TestNG should be used to execute the tests, configuring TestNG specific options.
|
Test |
workingDir(Object dir)
Sets the working directory for the process.
|
addTestListener, addTestOutputListener, afterSuite, afterTest, beforeSuite, beforeTest, getBinaryResultsDirectory, getBinResultsDir, getBuildOperationExecutor, getFilter, getIgnoreFailures, getInetAddressFactory, getInstantiator, getListenerManager, getProgressLoggerFactory, getReports, getTestLogging, getTextOutputFactory, onOutput, removeTestListener, removeTestOutputListener, reports, reports, setBinResultsDir, setIgnoreFailures, testLogging, testLoggingconventionMapping, conventionMapping, getConventionMappingnewInputDirectory, newInputFile, newOutputDirectory, newOutputFileaddValidator, appendParallelSafeAction, compareTo, configure, deleteAllActions, dependsOn, dependsOnTaskDidWork, doFirst, doFirst, doFirst, doLast, doLast, doLast, execute, finalizedBy, getActions, getAnt, getAsDynamicObject, getConvention, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExecuter, getExtensions, getFinalizedBy, getGroup, getIdentityPath, getImpliesSubProjects, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOnlyIf, getOutputs, getPath, getProject, getServices, getShouldRunAfter, getStandardOutputCapture, getState, getTaskActions, getTaskDependencies, getTemporaryDir, getTemporaryDirFactory, getValidators, hasProperty, injectIntoNewInstance, isEnabled, isHasCustomActions, leftShift, mustRunAfter, onlyIf, onlyIf, prependParallelSafeAction, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setExecuter, setFinalizedBy, setGroup, setImpliesSubProjects, setMustRunAfter, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, toString@Inject protected org.gradle.internal.actor.ActorFactory getActorFactory()
@Inject protected org.gradle.api.internal.initialization.loadercache.ClassLoaderCache getClassLoaderCache()
@Inject protected org.gradle.process.internal.worker.WorkerProcessFactory getProcessBuilderFactory()
@Inject protected org.gradle.api.internal.file.FileResolver getFileResolver()
@Inject protected org.gradle.api.internal.classpath.ModuleRegistry getModuleRegistry()
@Internal public File getWorkingDir()
getWorkingDir in interface ProcessForkOptionspublic void setWorkingDir(File dir)
setWorkingDir in interface ProcessForkOptionsdir - The working directory. Must not be null.public void setWorkingDir(Object dir)
Project.file(Object).setWorkingDir in interface ProcessForkOptionsdir - The working directory. Must not be null.public Test workingDir(Object dir)
Project.file(Object).workingDir in interface ProcessForkOptionsdir - The working directory. Must not be null.@Input public JavaVersion getJavaVersion()
getExecutable().@Internal public String getExecutable()
getExecutable in interface ProcessForkOptionspublic Test executable(Object executable)
executable in interface ProcessForkOptionsexecutable - The executable. Must not be null.public void setExecutable(String executable)
setExecutable in interface ProcessForkOptionsexecutable - The executable. Must not be null.public void setExecutable(Object executable)
setExecutable in interface ProcessForkOptionsexecutable - The executable. Must not be null.public Map<String,Object> getSystemProperties()
getSystemProperties in interface JavaForkOptionspublic void setSystemProperties(Map<String,?> properties)
setSystemProperties in interface JavaForkOptionsproperties - The system properties. Must not be null.public Test systemProperties(Map<String,?> properties)
systemProperties in interface JavaForkOptionsproperties - The system properties. Must not be null.public Test systemProperty(String name, Object value)
systemProperty in interface JavaForkOptionsname - The name of the propertyvalue - The value for the property. May be null.public FileCollection getBootstrapClasspath()
getBootstrapClasspath in interface JavaForkOptionspublic void setBootstrapClasspath(FileCollection classpath)
setBootstrapClasspath in interface JavaForkOptionsclasspath - The classpath. Must not be null. Can be empty.public Test bootstrapClasspath(Object... classpath)
bootstrapClasspath in interface JavaForkOptionsclasspath - The classpath.public String getMinHeapSize()
getMinHeapSize in interface JavaForkOptionspublic String getDefaultCharacterEncoding()
getDefaultCharacterEncoding in interface JavaForkOptionsdefault character encoding of this JVM should be used.public void setDefaultCharacterEncoding(String defaultCharacterEncoding)
file.encoding property). For JVMs
where this is the case, setting the file.encoding property via JavaForkOptions.setSystemProperties(java.util.Map) or similar will have no effect as
this value will be overridden by the value specified by JavaForkOptions.getDefaultCharacterEncoding().setDefaultCharacterEncoding in interface JavaForkOptionsdefaultCharacterEncoding - The default character encoding. Use null to use this JVM's default charsetpublic void setMinHeapSize(String heapSize)
setMinHeapSize in interface JavaForkOptionsheapSize - The minimum heap size. Use null for the default minimum heap size.public String getMaxHeapSize()
getMaxHeapSize in interface JavaForkOptionspublic void setMaxHeapSize(String heapSize)
setMaxHeapSize in interface JavaForkOptionsheapSize - The heap size. Use null for the default maximum heap size.public List<String> getJvmArgs()
getJvmArgs in interface JavaForkOptionspublic void setJvmArgs(List<String> arguments)
setJvmArgs in interface JavaForkOptionsarguments - The arguments. Must not be null.public void setJvmArgs(Iterable<?> arguments)
setJvmArgs in interface JavaForkOptionsarguments - The arguments. Must not be null.public Test jvmArgs(Iterable<?> arguments)
jvmArgs in interface JavaForkOptionsarguments - The arguments. Must not be null.public Test jvmArgs(Object... arguments)
jvmArgs in interface JavaForkOptionsarguments - The arguments.public boolean getEnableAssertions()
getEnableAssertions in interface JavaForkOptionspublic void setEnableAssertions(boolean enabled)
setEnableAssertions in interface JavaForkOptionsenabled - true to enable assertions, false to disable.public boolean getDebug()
getDebug in interface JavaForkOptionspublic void setDebug(boolean enabled)
setDebug in interface JavaForkOptionsenabled - true to enable debugging, false to disable.public List<String> getAllJvmArgs()
getAllJvmArgs in interface JavaForkOptionspublic void setAllJvmArgs(List<String> arguments)
setAllJvmArgs in interface JavaForkOptionsarguments - The arguments. Must not be null.public void setAllJvmArgs(Iterable<?> arguments)
setAllJvmArgs in interface JavaForkOptionsarguments - The arguments. Must not be null.@Internal public Map<String,Object> getEnvironment()
getEnvironment in interface ProcessForkOptionspublic Test environment(Map<String,?> environmentVariables)
environment in interface ProcessForkOptionsenvironmentVariables - The environment variables. Must not be null.public Test environment(String name, Object value)
environment in interface ProcessForkOptionsname - The name of the variable.value - The value for the variable. Must not be null.public void setEnvironment(Map<String,?> environmentVariables)
setEnvironment in interface ProcessForkOptionsenvironmentVariables - The environment variables. Must not be null.public Test copyTo(ProcessForkOptions target)
copyTo in interface ProcessForkOptionstarget - The target optionspublic Test copyTo(JavaForkOptions target)
copyTo in interface JavaForkOptionstarget - The target options.protected org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec createTestExecutionSpec()
createTestExecutionSpec in class AbstractTestTaskpublic void executeTests()
executeTests in class AbstractTestTaskprotected org.gradle.api.internal.tasks.testing.TestExecuter<org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec> createTestExecuter()
AbstractTestTaskcreateTestExecuter in class AbstractTestTaskprotected List<String> getNoMatchingTestErrorReasons()
AbstractTestTaskgetNoMatchingTestErrorReasons in class AbstractTestTaskpublic Test include(String... includes)
include in interface PatternFilterableincludes - a vararg list of include patternssetIncludes(Iterable)public Test include(Iterable<String> includes)
include in interface PatternFilterableincludes - a Iterable providing more include patternssetIncludes(Iterable)public Test include(Spec<FileTreeElement> includeSpec)
include in interface PatternFilterableincludeSpec - the spec to addPattern Formatpublic Test include(Closure includeSpec)
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.include in interface PatternFilterableincludeSpec - the spec to addPattern Formatpublic Test exclude(String... excludes)
exclude in interface PatternFilterableexcludes - a vararg list of exclude patternssetExcludes(Iterable)public Test exclude(Iterable<String> excludes)
exclude in interface PatternFilterableexcludes - a Iterable providing new exclude patternssetExcludes(Iterable)public Test exclude(Spec<FileTreeElement> excludeSpec)
exclude in interface PatternFilterableexcludeSpec - the spec to addPattern Formatpublic Test exclude(Closure excludeSpec)
FileTreeElement as its parameter. The closure should return true or false. Example:
copySpec {
from 'source'
into 'destination'
//an example of excluding files from certain configuration:
exclude { it.file in configurations.someConf.files }
}
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.exclude in interface PatternFilterableexcludeSpec - the spec to addFileTreeElementpublic Test setTestNameIncludePatterns(List<String> testNamePattern)
TestFiltersetTestNameIncludePatterns in class AbstractTestTask@Deprecated @Internal public File getTestClassesDir()
getTestClassesDirs().@Deprecated public void setTestClassesDir(File testClassesDir)
setTestClassesDirs(FileCollection).testClassesDir - The root folder@Internal public FileCollection getTestClassesDirs()
public void setTestClassesDirs(FileCollection testClassesDirs)
apply plugin: 'java'
sourceSets {
integrationTest {
compileClasspath += main.output
runtimeClasspath += main.output
}
}
task integrationTest(type: Test) {
// Runs tests from src/integrationTest
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
testClassesDirs - All test class directories to be used.@Internal public Set<String> getIncludes()
getIncludes in interface PatternFilterableinclude(String...)public Test setIncludes(Iterable<String> includes)
setIncludes in interface PatternFilterableincludes - The patterns listinclude(String...)@Internal public Set<String> getExcludes()
getExcludes in interface PatternFilterableexclude(String...)public Test setExcludes(Iterable<String> excludes)
setExcludes in interface PatternFilterableexcludes - The patterns listexclude(String...)@Internal public org.gradle.api.internal.tasks.testing.TestFramework getTestFramework()
public org.gradle.api.internal.tasks.testing.TestFramework testFramework(Closure testFrameworkConfigure)
public TestFrameworkOptions getOptions()
useJUnit() or useTestNG() before using this method.public TestFrameworkOptions options(Closure testFrameworkConfigure)
useJUnit() or useTestNG() before using this method.public TestFrameworkOptions options(Action<? super TestFrameworkOptions> testFrameworkConfigure)
useJUnit() or useTestNG() before using this method.public void useJUnit()
To configure JUnit specific options, see useJUnit(groovy.lang.Closure).
public void useJUnit(Closure testFrameworkConfigure)
The supplied closure configures an instance of JUnitOptions, which can be used to configure how JUnit runs.
testFrameworkConfigure - A closure used to configure the JUnit options.public void useJUnit(Action<? super JUnitOptions> testFrameworkConfigure)
The supplied action configures an instance of JUnitOptions, which can be used to configure how JUnit runs.
testFrameworkConfigure - An action used to configure the JUnit options.public void useTestNG()
To configure TestNG specific options, see useTestNG(Closure).
public void useTestNG(Closure testFrameworkConfigure)
The supplied closure configures an instance of TestNGOptions, which can be used to configure how TestNG runs.
testFrameworkConfigure - A closure used to configure the TestNG options.public void useTestNG(Action<? super TestFrameworkOptions> testFrameworkConfigure)
The supplied action configures an instance of TestNGOptions, which can be used to configure how TestNG runs.
testFrameworkConfigure - An action used to configure the TestNG options.@Classpath public FileCollection getClasspath()
public void setClasspath(FileCollection classpath)
@Input public boolean isScanForTestClasses()
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.public void setScanForTestClasses(boolean scanForTestClasses)
@Internal public long getForkEvery()
public void setForkEvery(Long forkEvery)
forkEvery - The maximum number of test classes. Use null or 0 to specify no maximum.@Internal public int getMaxParallelForks()
public void setMaxParallelForks(int maxParallelForks)
maxParallelForks - The maximum number of forked test processes.@PathSensitive(value=RELATIVE) @InputFiles public FileTree getCandidateClassFiles()
@Incubating public void filter(Action<TestFilter> action)
AbstractTestTask.getFilter().action - configuration of the test filter