|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.gradle.api.internal.AbstractTask org.gradle.api.DefaultTask org.gradle.api.internal.ConventionTask org.gradle.api.tasks.testing.Test
public class Test extends org.gradle.api.internal.ConventionTask
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 ) } }
Field Summary |
---|
Fields inherited from class org.gradle.api.internal.ConventionTask | |
---|---|
TASK_NAME, TASK_DESCRIPTION, TASK_GROUP, TASK_TYPE, TASK_DEPENDS_ON, TASK_OVERWRITE, TASK_ACTION |
Fields inherited from class DefaultTask | |
---|---|
TASK_NAME, TASK_DESCRIPTION, TASK_GROUP, TASK_TYPE, TASK_DEPENDS_ON, TASK_OVERWRITE, TASK_ACTION |
Constructor Summary | |
Test()
|
Method Summary | |
---|---|
void
|
addTestListener(TestListener listener)
Registers a test listener with this task. |
void
|
addTestOutputListener(TestOutputListener listener)
Registers a output listener with this task. |
void
|
afterSuite(groovy.lang.Closure closure)
|
void
|
afterTest(groovy.lang.Closure closure)
Adds a closure to be notified after a test has executed. |
void
|
beforeSuite(groovy.lang.Closure closure)
|
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)
{@inheritDoc} |
Test
|
exclude(groovy.lang.Closure excludeSpec)
{@inheritDoc} |
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()
|
java.util.Map
|
getSystemProperties()
{@inheritDoc} |
java.io.File
|
getTestClassesDir()
Returns the root folder for the compiled test sources. |
org.gradle.api.internal.tasks.testing.TestFramework
|
getTestFramework()
|
TestLogging
|
getTestLogging()
Allows configuring the logging of the test execution, for example log eagerly the standard output, etc. |
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)
{@inheritDoc} |
Test
|
include(groovy.lang.Closure includeSpec)
{@inheritDoc} |
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} |
void
|
onOutput(groovy.lang.Closure closure)
Adds a closure to be notified when output from the test received. |
TestFrameworkOptions
|
options(groovy.lang.Closure testFrameworkConfigure)
|
void
|
removeTestListener(TestListener listener)
Unregisters a test listener with this task. |
void
|
removeTestOutputListener(TestOutputListener listener)
Unregisters a test output 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} |
org.gradle.api.internal.tasks.testing.TestFramework
|
testFramework(groovy.lang.Closure testFrameworkConfigure)
|
void
|
testLogging(groovy.lang.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(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} |
Methods inherited from class org.gradle.api.internal.ConventionTask | |
---|---|
org.gradle.api.internal.ConventionTask#conventionMapping(java.lang.String, org.gradle.api.tasks.ConventionValue), org.gradle.api.internal.ConventionTask#getConventionMapping(), org.gradle.api.internal.ConventionTask#setConventionMapping(org.gradle.api.internal.ConventionMapping), org.gradle.api.internal.ConventionTask#setProperty(java.lang.String, java.lang.Object), org.gradle.api.internal.ConventionTask#toString(), org.gradle.api.internal.ConventionTask#compareTo(org.gradle.api.Task), org.gradle.api.internal.ConventionTask#compareTo(java.lang.Object), org.gradle.api.internal.ConventionTask#getName(), org.gradle.api.internal.ConventionTask#getActions(), org.gradle.api.internal.ConventionTask#setName(java.lang.String), org.gradle.api.internal.ConventionTask#getState(), org.gradle.api.internal.ConventionTask#getPath(), org.gradle.api.internal.ConventionTask#getLogger(), org.gradle.api.internal.ConventionTask#leftShift(groovy.lang.Closure), org.gradle.api.internal.ConventionTask#execute(), org.gradle.api.internal.ConventionTask#configure(groovy.lang.Closure), org.gradle.api.internal.ConventionTask#configure(groovy.lang.Closure), org.gradle.api.internal.ConventionTask#isEnabled(), org.gradle.api.internal.ConventionTask#getDescription(), org.gradle.api.internal.ConventionTask#captureStandardOutput(org.gradle.api.logging.LogLevel), org.gradle.api.internal.ConventionTask#disableStandardOutputCapture(), org.gradle.api.internal.ConventionTask#property(java.lang.String), org.gradle.api.internal.ConventionTask#setEnabled(boolean), org.gradle.api.internal.ConventionTask#getOutputs(), org.gradle.api.internal.ConventionTask#getOutputs(), org.gradle.api.internal.ConventionTask#getProject(), org.gradle.api.internal.ConventionTask#setActions(java.util.List), org.gradle.api.internal.ConventionTask#getTaskDependencies(), org.gradle.api.internal.ConventionTask#getTaskDependencies(), org.gradle.api.internal.ConventionTask#getDependsOn(), org.gradle.api.internal.ConventionTask#setDependsOn(java.lang.Iterable), org.gradle.api.internal.ConventionTask#dependsOn([Ljava.lang.Object;), org.gradle.api.internal.ConventionTask#onlyIf(org.gradle.api.specs.Spec), org.gradle.api.internal.ConventionTask#onlyIf(groovy.lang.Closure), org.gradle.api.internal.ConventionTask#setOnlyIf(groovy.lang.Closure), org.gradle.api.internal.ConventionTask#setOnlyIf(org.gradle.api.specs.Spec), org.gradle.api.internal.ConventionTask#setDidWork(boolean), org.gradle.api.internal.ConventionTask#getDidWork(), org.gradle.api.internal.ConventionTask#doFirst(org.gradle.api.Action), org.gradle.api.internal.ConventionTask#doFirst(groovy.lang.Closure), org.gradle.api.internal.ConventionTask#doLast(org.gradle.api.Action), org.gradle.api.internal.ConventionTask#doLast(groovy.lang.Closure), org.gradle.api.internal.ConventionTask#deleteAllActions(), org.gradle.api.internal.ConventionTask#getEnabled(), org.gradle.api.internal.ConventionTask#getAnt(), org.gradle.api.internal.ConventionTask#getLogging(), org.gradle.api.internal.ConventionTask#hasProperty(java.lang.String), org.gradle.api.internal.ConventionTask#getConvention(), org.gradle.api.internal.ConventionTask#setDescription(java.lang.String), org.gradle.api.internal.ConventionTask#getGroup(), org.gradle.api.internal.ConventionTask#setGroup(java.lang.String), org.gradle.api.internal.ConventionTask#dependsOnTaskDidWork(), org.gradle.api.internal.ConventionTask#getInputs(), org.gradle.api.internal.ConventionTask#getTemporaryDir(), org.gradle.api.internal.ConventionTask#getExtensions(), org.gradle.api.internal.ConventionTask#getAsDynamicObject(), org.gradle.api.internal.ConventionTask#getAdditionalProperties(), org.gradle.api.internal.ConventionTask#getStandardOutputCapture(), org.gradle.api.internal.ConventionTask#executeWithoutThrowingTaskFailure(), org.gradle.api.internal.ConventionTask#setProject(org.gradle.api.Project), org.gradle.api.internal.ConventionTask#getDynamicObjectHelper(), org.gradle.api.internal.ConventionTask#addValidator(org.gradle.api.internal.tasks.execution.TaskValidator), org.gradle.api.internal.ConventionTask#getValidators(), org.gradle.api.internal.ConventionTask#getExecuter(), org.gradle.api.internal.ConventionTask#setExecuter(org.gradle.api.internal.tasks.TaskExecuter), org.gradle.api.internal.ConventionTask#getOnlyIf(), org.gradle.api.internal.ConventionTask#getTemporaryDirFactory(), org.gradle.api.internal.ConventionTask#injectIntoNewInstance(org.gradle.api.internal.project.ProjectInternal, java.lang.String, java.util.concurrent.Callable), org.gradle.api.internal.ConventionTask#wait(), org.gradle.api.internal.ConventionTask#wait(long), org.gradle.api.internal.ConventionTask#wait(long, int), org.gradle.api.internal.ConventionTask#equals(java.lang.Object), org.gradle.api.internal.ConventionTask#hashCode(), org.gradle.api.internal.ConventionTask#getClass(), org.gradle.api.internal.ConventionTask#notify(), org.gradle.api.internal.ConventionTask#notifyAll() |
Constructor Detail |
---|
public Test()
Method Detail |
---|
public void addTestListener(TestListener listener)
This listener will NOT be notified of tests executed by other tasks. To get that behavior, use Gradle.addListener.
listener
- The listener to add.
public void addTestOutputListener(TestOutputListener listener)
listener
- The listener to add.
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.
closure
- The closure to call.
public void afterTest(groovy.lang.Closure closure)
closure
- The closure to call.
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.
closure
- The closure to call.
public void beforeTest(groovy.lang.Closure closure)
closure
- The closure to call.
public Test bootstrapClasspath(java.lang.Object... classpath)
public Test copyTo(ProcessForkOptions target)
public Test copyTo(JavaForkOptions target)
public void disableTestReport()
public void enableTestReport()
public Test environment(java.util.Map environmentVariables)
public Test environment(java.lang.String name, java.lang.Object value)
public Test exclude(java.lang.String... excludes)
public Test exclude(java.lang.Iterable excludes)
public Test exclude(Spec excludeSpec)
public Test exclude(groovy.lang.Closure excludeSpec)
public Test executable(java.lang.Object executable)
@TaskAction public void executeTests()
public java.util.List getAllJvmArgs()
@Input public FileCollection getBootstrapClasspath()
@InputFiles @Input // Also marked as input to force tests to run when the set of candidate class files changes public FileTree getCandidateClassFiles()
@InputFiles public FileCollection getClasspath()
public boolean getDebug()
@Input public boolean getEnableAssertions()
public java.util.Map getEnvironment()
public java.util.Set getExcludes()
@Input public java.lang.String getExecutable()
public long getForkEvery()
public java.util.Set getIncludes()
@Input public java.util.List getJvmArgs()
public java.lang.String getMaxHeapSize()
public int getMaxParallelForks()
@Nested public TestFrameworkOptions getOptions()
Returns the test options options.
Be sure to call the appropriate useJUnit() or useTestNG() method before using this method.
@Input public java.util.Map getSystemProperties()
public java.io.File getTestClassesDir()
public org.gradle.api.internal.tasks.testing.TestFramework getTestFramework()
public TestLogging getTestLogging()
apply plugin: 'java' //makes the standard streams (err and out) visible at console when running tests test.testLogging.showStandardStreams = true
@OutputDirectory public java.io.File getTestReportDir()
@OutputDirectory public java.io.File getTestResultsDir()
@InputFiles public java.util.List getTestSrcDirs()
@Input public java.io.File getWorkingDir()
public Test include(java.lang.String... includes)
public Test include(java.lang.Iterable includes)
public Test include(Spec includeSpec)
public Test include(groovy.lang.Closure includeSpec)
@Input public boolean isIgnoreFailures()
@Input public boolean isScanForTestClasses()
@Input public boolean isTestReport()
public Test jvmArgs(java.lang.Iterable arguments)
public Test jvmArgs(java.lang.Object... arguments)
public void onOutput(groovy.lang.Closure closure)
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 TestFrameworkOptions options(groovy.lang.Closure testFrameworkConfigure)
public void removeTestListener(TestListener listener)
listener
- The listener to remove.
public void removeTestOutputListener(TestOutputListener listener)
listener
- The listener to remove.
public void setAllJvmArgs(java.lang.Iterable arguments)
public void setBootstrapClasspath(FileCollection classpath)
public void setClasspath(FileCollection classpath)
public void setDebug(boolean enabled)
public void setEnableAssertions(boolean enabled)
public void setEnvironment(java.util.Map environmentVariables)
public Test setExcludes(java.lang.Iterable excludes)
excludes
- The patterns list
public void setExecutable(java.lang.Object executable)
public void setForkEvery(java.lang.Long forkEvery)
forkEvery
- The maximum number of test classes. Use null or 0 to specify no maximum.
public Test setIgnoreFailures(boolean ignoreFailures)
public Test setIncludes(java.lang.Iterable includes)
includes
- The patterns list
public void setJvmArgs(java.lang.Iterable arguments)
public void setMaxHeapSize(java.lang.String heapSize)
public void setMaxParallelForks(int maxParallelForks)
maxParallelForks
- The maximum number of forked test processes.
public void setScanForTestClasses(boolean scanForTestClasses)
public void setSystemProperties(java.util.Map properties)
public void setTestClassesDir(java.io.File testClassesDir)
testClassesDir
- The root folder
public void setTestReport(boolean testReport)
public void setTestReportDir(java.io.File testReportDir)
testReportDir
- The root folder
public void setTestResultsDir(java.io.File testResultsDir)
testResultsDir
- The root folder
public void setTestSrcDirs(java.util.List testSrcDir)
public void setWorkingDir(java.lang.Object dir)
public Test systemProperties(java.util.Map properties)
public Test systemProperty(java.lang.String name, java.lang.Object value)
public org.gradle.api.internal.tasks.testing.TestFramework testFramework(groovy.lang.Closure testFrameworkConfigure)
public void testLogging(groovy.lang.Closure closure)
apply plugin: 'java' //makes the standard streams (err and out) visible at console when running tests test.testLogging { showStandardStreams = true }
closure
- configure closure
public void useJUnit()
public void useJUnit(groovy.lang.Closure testFrameworkConfigure)
testFrameworkConfigure
- A closure used to configure the JUint options. This closure is passed an instance
of type JUnitOptions.
public void useTestNG()
public void useTestNG(groovy.lang.Closure testFrameworkConfigure)
testFrameworkConfigure
- A closure used to configure the JUint options. This closure is passed an instance
of type TestNGOptions.
public Test workingDir(java.lang.Object dir)
Groovy Documentation