public class Test extends org.gradle.api.internal.ConventionTask implements JavaForkOptions, PatternFilterable, VerificationTask, Reporting<TestTaskReports>
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.Namer
TASK_ACTION, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
コンストラクタと説明 |
---|
Test() |
修飾子とタイプ | メソッドと説明 |
---|---|
void |
addTestListener(TestListener listener)
Registers a test listener with this task.
|
void |
addTestOutputListener(TestOutputListener listener)
Registers a output listener with this task.
|
void |
afterSuite(Closure closure)
Adds a closure to be notified after a test suite has executed.
|
void |
afterTest(Closure closure)
Adds a closure to be notified after a test has executed.
|
void |
beforeSuite(Closure closure)
Adds a closure to be notified before a test suite is executed.
|
void |
beforeTest(Closure closure)
Adds a closure to be notified before a test is executed.
|
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.
|
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. '**F;*Test.class')).
|
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. '**F;*Test.class')).
|
Test |
executable(Object executable)
Sets the name of the executable to use.
|
void |
executeTests() |
void |
filter(Action<TestFilter> action)
Executes the action against the
getFilter() . |
protected org.gradle.messaging.actor.ActorFactory |
getActorFactory() |
List<String> |
getAllJvmArgs()
Returns the full set of arguments to use to launch the JVM for the process.
|
File |
getBinResultsDir()
Returns the root folder for the test results in internal binary format.
|
FileCollection |
getBootstrapClasspath()
Returns the bootstrap classpath to use for the process.
|
FileTree |
getCandidateClassFiles()
Returns the classes files to scan for test classes.
|
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() |
TestFilter |
getFilter()
Allows filtering tests for execution.
|
long |
getForkEvery()
Returns the maximum number of test classes to execute in a forked test process.
|
boolean |
getIgnoreFailures()
Specifies whether the build should break when the verifications performed by this task fail.
|
Set<String> |
getIncludes()
Returns the include patterns for test execution.
|
protected org.gradle.internal.reflect.Instantiator |
getInstantiator() |
List<String> |
getJvmArgs()
Returns the extra arguments to use to launch the JVM for the process.
|
protected org.gradle.listener.ListenerManager |
getListenerManager() |
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.
|
TestFrameworkOptions |
getOptions()
Returns test framework specific options.
|
protected org.gradle.internal.Factory<org.gradle.process.internal.WorkerProcessBuilder> |
getProcessBuilderFactory() |
protected org.gradle.logging.ProgressLoggerFactory |
getProgressLoggerFactory() |
TestTaskReports |
getReports()
The reports that this task potentially produces.
|
Map<String,Object> |
getSystemProperties()
Returns the system properties which will be used for the process.
|
File |
getTestClassesDir()
Returns the root folder for the compiled test sources.
|
org.gradle.api.internal.tasks.testing.TestFramework |
getTestFramework() |
TestLoggingContainer |
getTestLogging()
Allows to set options related to which test events are logged to the console, and on which detail level.
|
List<File> |
getTestSrcDirs()
Returns the directories containing the test source.
|
protected org.gradle.logging.StyledTextOutputFactory |
getTextOutputFactory() |
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. '**F;*Test.class')).
|
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. '**F;*Test.class')).
|
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.
|
void |
onOutput(Closure closure)
Adds a closure to be notified when output from the test received.
|
TestFrameworkOptions |
options(Closure testFrameworkConfigure)
Configures test framework specific options.
|
void |
removeTestListener(TestListener listener)
Unregisters a test listener with this task.
|
void |
removeTestOutputListener(TestOutputListener listener)
Unregisters a test output listener with this task.
|
TestTaskReports |
reports(Closure closure)
Configures the reports that this task potentially produces.
|
void |
setAllJvmArgs(Iterable<?> arguments)
Sets the full set of arguments to use to launch the JVM for the process.
|
void |
setBinResultsDir(File binResultsDir)
Sets the root folder for the test results in internal binary format.
|
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 |
setForkEvery(Long forkEvery)
Sets the maximum number of test classes to execute in a forked test process.
|
void |
setIgnoreFailures(boolean ignoreFailures)
Specifies whether the build should break when the verifications performed by this task fail.
|
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 |
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)
Sets the root folder for the compiled test sources.
|
Test |
setTestNameIncludePattern(String testNamePattern)
Sets the test name patterns to be included in execution.
|
void |
setTestSrcDirs(List<File> testSrcDir) |
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 |
testLogging(Closure closure)
Allows configuring the logging of the test execution, for example log eagerly the standard output, etc.
|
void |
useJUnit()
Specifies that JUnit should be used to execute the tests.
|
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(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.
|
conventionMapping, conventionMapping, getConventionMapping
addValidator, compareTo, configure, deleteAllActions, dependsOn, dependsOnTaskDidWork, doFirst, doFirst, doLast, doLast, execute, executeWithoutThrowingTaskFailure, finalizedBy, getActions, getAnt, getAsDynamicObject, getConvention, getDependsOn, getDescription, getDidWork, getEnabled, getExecuter, getExtensions, getFinalizedBy, getGroup, getImpliesSubProjects, getInputs, getLogger, getLogging, getMustRunAfter, getName, getOnlyIf, getOutputs, getPath, getProject, getServices, getShouldRunAfter, getStandardOutputCapture, getState, getTaskActions, getTaskDependencies, getTemporaryDir, getTemporaryDirFactory, getValidators, hasProperty, injectIntoNewInstance, isEnabled, leftShift, mustRunAfter, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setExecuter, setFinalizedBy, setGroup, setImpliesSubProjects, setMustRunAfter, setName, setOnlyIf, setOnlyIf, setProject, setProperty, setShouldRunAfter, shouldRunAfter, toString
@Inject protected org.gradle.logging.ProgressLoggerFactory getProgressLoggerFactory()
@Inject protected org.gradle.internal.reflect.Instantiator getInstantiator()
@Inject protected org.gradle.messaging.actor.ActorFactory getActorFactory()
@Inject protected org.gradle.internal.Factory<org.gradle.process.internal.WorkerProcessBuilder> getProcessBuilderFactory()
@Inject protected org.gradle.api.internal.file.FileResolver getFileResolver()
@Inject protected org.gradle.logging.StyledTextOutputFactory getTextOutputFactory()
@Inject protected org.gradle.listener.ListenerManager getListenerManager()
@Input public File getWorkingDir()
getWorkingDir
インタフェース内 ProcessForkOptions
public void setWorkingDir(Object dir)
Project.file(Object)
.setWorkingDir
インタフェース内 ProcessForkOptions
dir
- The working directory. Must not be null.public Test workingDir(Object dir)
Project.file(Object)
.workingDir
インタフェース内 ProcessForkOptions
dir
- The working directory. Must not be null.@Input public String getExecutable()
getExecutable
インタフェース内 ProcessForkOptions
public Test executable(Object executable)
executable
インタフェース内 ProcessForkOptions
executable
- The executable. Must not be null.public void setExecutable(Object executable)
setExecutable
インタフェース内 ProcessForkOptions
executable
- The executable. Must not be null.@Input public Map<String,Object> getSystemProperties()
getSystemProperties
インタフェース内 JavaForkOptions
public void setSystemProperties(Map<String,?> properties)
setSystemProperties
インタフェース内 JavaForkOptions
properties
- The system properties. Must not be null.public Test systemProperties(Map<String,?> properties)
systemProperties
インタフェース内 JavaForkOptions
properties
- The system properties. Must not be null.public Test systemProperty(String name, Object value)
systemProperty
インタフェース内 JavaForkOptions
name
- The name of the propertyvalue
- The value for the property. May be null.@Input public FileCollection getBootstrapClasspath()
getBootstrapClasspath
インタフェース内 JavaForkOptions
public void setBootstrapClasspath(FileCollection classpath)
setBootstrapClasspath
インタフェース内 JavaForkOptions
classpath
- The classpath. Must not be null. Can be empty.public Test bootstrapClasspath(Object... classpath)
bootstrapClasspath
インタフェース内 JavaForkOptions
classpath
- The classpath.public String getMinHeapSize()
getMinHeapSize
インタフェース内 JavaForkOptions
public String getDefaultCharacterEncoding()
getDefaultCharacterEncoding
インタフェース内 JavaForkOptions
default 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
インタフェース内 JavaForkOptions
defaultCharacterEncoding
- The default character encoding. Use null to use this JVM's default charset
public void setMinHeapSize(String heapSize)
setMinHeapSize
インタフェース内 JavaForkOptions
heapSize
- The minimum heap size. Use null for the default minimum heap size.public String getMaxHeapSize()
getMaxHeapSize
インタフェース内 JavaForkOptions
public void setMaxHeapSize(String heapSize)
setMaxHeapSize
インタフェース内 JavaForkOptions
heapSize
- The heap size. Use null for the default maximum heap size.@Input public List<String> getJvmArgs()
getJvmArgs
インタフェース内 JavaForkOptions
public void setJvmArgs(Iterable<?> arguments)
setJvmArgs
インタフェース内 JavaForkOptions
arguments
- The arguments. Must not be null.public Test jvmArgs(Iterable<?> arguments)
jvmArgs
インタフェース内 JavaForkOptions
arguments
- The arguments. Must not be null.public Test jvmArgs(Object... arguments)
jvmArgs
インタフェース内 JavaForkOptions
arguments
- The arguments.@Input public boolean getEnableAssertions()
getEnableAssertions
インタフェース内 JavaForkOptions
public void setEnableAssertions(boolean enabled)
setEnableAssertions
インタフェース内 JavaForkOptions
enabled
- true to enable assertions, false to disable.public boolean getDebug()
getDebug
インタフェース内 JavaForkOptions
public void setDebug(boolean enabled)
setDebug
インタフェース内 JavaForkOptions
enabled
- true to enable debugging, false to disable.public List<String> getAllJvmArgs()
getAllJvmArgs
インタフェース内 JavaForkOptions
public void setAllJvmArgs(Iterable<?> arguments)
setAllJvmArgs
インタフェース内 JavaForkOptions
arguments
- The arguments. Must not be null.public Map<String,Object> getEnvironment()
getEnvironment
インタフェース内 ProcessForkOptions
public Test environment(Map<String,?> environmentVariables)
environment
インタフェース内 ProcessForkOptions
environmentVariables
- The environment variables. Must not be null.public Test environment(String name, Object value)
environment
インタフェース内 ProcessForkOptions
name
- The name of the variable.value
- The value for the variable. Must not be null.public void setEnvironment(Map<String,?> environmentVariables)
setEnvironment
インタフェース内 ProcessForkOptions
environmentVariables
- The environment variables. Must not be null.public Test copyTo(ProcessForkOptions target)
copyTo
インタフェース内 ProcessForkOptions
target
- The target optionspublic Test copyTo(JavaForkOptions target)
copyTo
インタフェース内 JavaForkOptions
target
- The target options.public void executeTests()
public void addTestListener(TestListener listener)
beforeTest(groovy.lang.Closure)
, afterTest(groovy.lang.Closure)
, beforeSuite(groovy.lang.Closure)
, afterSuite(groovy.lang.Closure)
This listener will NOT be notified of tests executed by other tasks. To
get that behavior, use Gradle.addListener(Object)
.
listener
- The listener to add.public void addTestOutputListener(TestOutputListener listener)
onOutput(groovy.lang.Closure)
method.listener
- The listener to add.public void removeTestListener(TestListener listener)
addTestListener(org.gradle.api.tasks.testing.TestListener)
on this task.
If the listener was registered with Gradle using Gradle.addListener(Object)
this method will not do anything. Instead, use Gradle.removeListener(Object)
.listener
- The listener to remove.public void removeTestOutputListener(TestOutputListener listener)
addTestOutputListener(org.gradle.api.tasks.testing.TestOutputListener)
on this task. If the listener was registered with Gradle using Gradle.addListener(Object)
this method will not do anything. Instead, use Gradle.removeListener(Object)
.listener
- The listener to remove.public 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.
closure
- The closure to call.public 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.
closure
- The closure to call.public void beforeTest(Closure closure)
TestDescriptor
instance is passed to the closure as a parameter.closure
- The closure to call.public void afterTest(Closure closure)
TestDescriptor
and TestResult
instance are passed to the closure as a parameter.closure
- The closure to call.public void onOutput(Closure closure)
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) } } }
closure
- The closure to call.public Test include(String... includes)
include
インタフェース内 PatternFilterable
includes
- a vararg list of include patternssetIncludes(Iterable)
public Test include(Iterable<String> includes)
include
インタフェース内 PatternFilterable
includes
- a Iterable providing more include patternssetIncludes(Iterable)
public Test include(Spec<FileTreeElement> includeSpec)
include
インタフェース内 PatternFilterable
includeSpec
- the spec to addPattern Format
public 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
インタフェース内 PatternFilterable
includeSpec
- the spec to addPattern Format
public Test exclude(String... excludes)
exclude
インタフェース内 PatternFilterable
excludes
- a vararg list of exclude patternssetExcludes(Iterable)
public Test exclude(Iterable<String> excludes)
exclude
インタフェース内 PatternFilterable
excludes
- a Iterable providing new exclude patternssetExcludes(Iterable)
public Test exclude(Spec<FileTreeElement> excludeSpec)
exclude
インタフェース内 PatternFilterable
excludeSpec
- the spec to addPattern Format
public 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
インタフェース内 PatternFilterable
excludeSpec
- the spec to addFileTreeElement
@Incubating public Test setTestNameIncludePattern(String testNamePattern)
TestFilter
public File getTestClassesDir()
public void setTestClassesDir(File testClassesDir)
testClassesDir
- The root folder@OutputDirectory @Incubating public File getBinResultsDir()
@Incubating public void setBinResultsDir(File binResultsDir)
binResultsDir
- The root folderpublic Set<String> getIncludes()
getIncludes
インタフェース内 PatternFilterable
include(String...)
public Test setIncludes(Iterable<String> includes)
setIncludes
インタフェース内 PatternFilterable
includes
- The patterns listinclude(String...)
public Set<String> getExcludes()
getExcludes
インタフェース内 PatternFilterable
exclude(String...)
public Test setExcludes(Iterable<String> excludes)
setExcludes
インタフェース内 PatternFilterable
excludes
- The patterns listexclude(String...)
@Input public boolean getIgnoreFailures()
getIgnoreFailures
インタフェース内 VerificationTask
public void setIgnoreFailures(boolean ignoreFailures)
setIgnoreFailures
インタフェース内 VerificationTask
ignoreFailures
- false to break the build on failure, true to ignore the failures. The default is false.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 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 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.@InputFiles public FileCollection getClasspath()
public void setClasspath(FileCollection classpath)
@InputFiles public List<File> getTestSrcDirs()
@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)
public long getForkEvery()
public void setForkEvery(Long forkEvery)
forkEvery
- The maximum number of test classes. Use null or 0 to specify no maximum.public int getMaxParallelForks()
public void setMaxParallelForks(int maxParallelForks)
maxParallelForks
- The maximum number of forked test processes.@InputFiles @Input public FileTree getCandidateClassFiles()
public TestLoggingContainer getTestLogging()
apply plugin: 'java' test.testLogging { exceptionFormat "full" }For further information see
TestLoggingContainer
.public void testLogging(Closure closure)
apply plugin: 'java' //makes the standard streams (err and out) visible at console when running tests test.testLogging { showStandardStreams = true }
closure
- configure closurepublic TestTaskReports getReports()
getReports
インタフェース内 Reporting<TestTaskReports>
public TestTaskReports reports(Closure closure)
reports
インタフェース内 Reporting<TestTaskReports>
closure
- The configuration@Incubating public TestFilter getFilter()
@Incubating public void filter(Action<TestFilter> action)
getFilter()
.action
- configuration of the test filter