|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.gradle.api.internal.ConventionTask org.gradle.api.tasks.testing.Test
public class Test extends ConventionTask
Executes JUnit (3.8.x or 4.x) or TestNG tests. Test are always run in (one or more) separate JVMs. The sample below shows various configuration options.
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
Constructor Summary | |
Test(ListenerManager listenerManager, StyledTextOutputFactory textOutputFactory, FileResolver fileResolver, Factory processBuilderFactory, ActorFactory actorFactory, Instantiator instantiator, ProgressLoggerFactory progressLoggerFactory)
|
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(Closure closure)
|
void
|
afterTest(Closure closure)
Adds a closure to be notified after a test has executed. |
void
|
beforeSuite(Closure closure)
|
void
|
beforeTest(Closure closure)
Adds a closure to be notified before a test is executed. |
Test
|
bootstrapClasspath(Object... classpath)
{@inheritDoc} |
Test
|
copyTo(ProcessForkOptions target)
{@inheritDoc} |
Test
|
copyTo(JavaForkOptions target)
{@inheritDoc} |
void
|
disableTestReport()
Disables the HTML test report. |
void
|
enableTestReport()
Enables the HTML test report. |
Test
|
environment(Map environmentVariables)
{@inheritDoc} |
Test
|
environment(String name, Object value)
{@inheritDoc} |
Test
|
exclude(String... excludes)
Adds exclude patterns for the files in the test classes directory (e.g. '**F;*Test.class')). |
Test
|
exclude(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(Closure excludeSpec)
{@inheritDoc} |
Test
|
executable(Object executable)
{@inheritDoc} |
void
|
executeTests()
|
void
|
filter(Action action)
Executes the action against the getFilter(). |
List
|
getAllJvmArgs()
{@inheritDoc} |
File
|
getBinResultsDir()
Returns the root folder for the test results in internal binary format. |
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} |
String
|
getDefaultCharacterEncoding()
{@inheritDoc} |
boolean
|
getEnableAssertions()
{@inheritDoc} |
Map
|
getEnvironment()
{@inheritDoc} |
Set
|
getExcludes()
Returns the exclude patterns for test execution. |
String
|
getExecutable()
{@inheritDoc} |
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()
{@inheritDoc} |
Set
|
getIncludes()
Returns the include patterns for test execution. |
List
|
getJvmArgs()
{@inheritDoc} |
String
|
getMaxHeapSize()
{@inheritDoc} |
int
|
getMaxParallelForks()
Returns the maximum number of forked test processes to execute in parallel. |
String
|
getMinHeapSize()
{@inheritDoc} |
TestFrameworkOptions
|
getOptions()
Returns test framework specific options. |
TestTaskReports
|
getReports()
The reports that this task potentially produces. |
Map
|
getSystemProperties()
{@inheritDoc} |
File
|
getTestClassesDir()
Returns the root folder for the compiled test sources. |
TestFramework
|
getTestFramework()
|
TestLoggingContainer
|
getTestLogging()
Allows to set options related to which test events are logged to the console, and on which detail level. |
File
|
getTestReportDir()
Returns the root folder for the test reports. |
File
|
getTestResultsDir()
Returns the root folder for the test results in XML format. |
List
|
getTestSrcDirs()
Returns the directories containing the test source. |
File
|
getWorkingDir()
{@inheritDoc} |
Test
|
include(String... includes)
Adds include patterns for the files in the test classes directory (e.g. '**F;*Test.class')). |
Test
|
include(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(Closure includeSpec)
{@inheritDoc} |
boolean
|
isScanForTestClasses()
Specifies whether test classes should be detected. |
boolean
|
isTestReport()
Specifies whether the test HTML report should be generated. |
Test
|
jvmArgs(Iterable arguments)
{@inheritDoc} |
Test
|
jvmArgs(Object... arguments)
{@inheritDoc} |
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)
{@inheritDoc} |
void
|
setBinResultsDir(File binResultsDir)
Sets the root folder for the test results in internal binary format. |
void
|
setBootstrapClasspath(FileCollection classpath)
{@inheritDoc} |
void
|
setClasspath(FileCollection classpath)
|
void
|
setDebug(boolean enabled)
{@inheritDoc} |
void
|
setDefaultCharacterEncoding(String defaultCharacterEncoding)
{@inheritDoc} |
void
|
setEnableAssertions(boolean enabled)
{@inheritDoc} |
void
|
setEnvironment(Map environmentVariables)
{@inheritDoc} |
Test
|
setExcludes(Iterable excludes)
Sets the exclude patterns for test execution. |
void
|
setExecutable(Object executable)
{@inheritDoc} |
void
|
setForkEvery(Long forkEvery)
Sets the maximum number of test classes to execute in a forked test process. |
void
|
setIgnoreFailures(boolean ignoreFailures)
{@inheritDoc} |
Test
|
setIncludes(Iterable includes)
Sets the include patterns for test execution. |
void
|
setJvmArgs(Iterable arguments)
{@inheritDoc} |
void
|
setMaxHeapSize(String heapSize)
{@inheritDoc} |
void
|
setMaxParallelForks(int maxParallelForks)
Sets the maximum number of forked test processes to execute in parallel. |
void
|
setMinHeapSize(String heapSize)
{@inheritDoc} |
void
|
setScanForTestClasses(boolean scanForTestClasses)
|
void
|
setSystemProperties(Map properties)
{@inheritDoc} |
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
|
setTestReport(boolean testReport)
Sets whether the test HTML report should be generated. |
void
|
setTestReportDir(File testReportDir)
Sets the root folder for the test reports. |
void
|
setTestResultsDir(File testResultsDir)
Sets the root folder for the test results. |
void
|
setTestSrcDirs(List testSrcDir)
|
void
|
setWorkingDir(Object dir)
{@inheritDoc} |
Test
|
systemProperties(Map properties)
{@inheritDoc} |
Test
|
systemProperty(String name, Object value)
{@inheritDoc} |
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)
{@inheritDoc} |
Constructor Detail |
---|
@Inject public Test(ListenerManager listenerManager, StyledTextOutputFactory textOutputFactory, FileResolver fileResolver, Factory processBuilderFactory, ActorFactory actorFactory, Instantiator instantiator, ProgressLoggerFactory progressLoggerFactory)
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(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(Closure closure)
closure
- The closure to call.
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 beforeTest(Closure closure)
closure
- The closure to call.
public Test bootstrapClasspath(Object... classpath)
public Test copyTo(ProcessForkOptions target)
public Test copyTo(JavaForkOptions target)
@SuppressWarnings("UnusedDeclaration") @Deprecated public void disableTestReport()
@SuppressWarnings("UnusedDeclaration") @Deprecated public void enableTestReport()
public Test environment(Map environmentVariables)
public Test environment(String name, Object value)
public Test exclude(String... excludes)
public Test exclude(Iterable excludes)
public Test exclude(Spec excludeSpec)
public Test exclude(Closure excludeSpec)
public Test executable(Object executable)
@TaskAction public void executeTests()
@Incubating public void filter(Action action)
action
- configuration of the test filter
public List getAllJvmArgs()
@OutputDirectory @Incubating public File getBinResultsDir()
@Input public FileCollection getBootstrapClasspath()
@InputFiles @Input public FileTree getCandidateClassFiles()
@InputFiles public FileCollection getClasspath()
public boolean getDebug()
public String getDefaultCharacterEncoding()
@Input public boolean getEnableAssertions()
public Map getEnvironment()
public Set getExcludes()
@Input public String getExecutable()
@Incubating @Nested public TestFilter getFilter()
public long getForkEvery()
@Input public boolean getIgnoreFailures()
public Set getIncludes()
@Input public List getJvmArgs()
public String getMaxHeapSize()
public int getMaxParallelForks()
public String getMinHeapSize()
@Nested public TestFrameworkOptions getOptions()
public TestTaskReports getReports()
@Input public Map getSystemProperties()
public File getTestClassesDir()
public TestFramework getTestFramework()
public TestLoggingContainer getTestLogging()
apply plugin: 'java' test.testLogging { exceptionFormat "full" }For further information see TestLoggingContainer.
@Deprecated public File getTestReportDir()
@Deprecated public File getTestResultsDir()
@InputFiles public List getTestSrcDirs()
@Input public File getWorkingDir()
public Test include(String... includes)
public Test include(Iterable includes)
public Test include(Spec includeSpec)
public Test include(Closure includeSpec)
@Input public boolean isScanForTestClasses()
@Deprecated public boolean isTestReport()
public Test jvmArgs(Iterable arguments)
public Test jvmArgs(Object... arguments)
public void onOutput(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(Closure testFrameworkConfigure)
public void removeTestListener(TestListener listener)
listener
- The listener to remove.
public void removeTestOutputListener(TestOutputListener listener)
listener
- The listener to remove.
public TestTaskReports reports(Closure closure)
closure
- The configuration
public void setAllJvmArgs(Iterable arguments)
@Incubating public void setBinResultsDir(File binResultsDir)
binResultsDir
- The root folder
public void setBootstrapClasspath(FileCollection classpath)
public void setClasspath(FileCollection classpath)
@Option(option = "debug-jvm", description = "Enable debugging for the test process. The process is started suspended and listening on port 5005. [INCUBATING]") public void setDebug(boolean enabled)
public void setDefaultCharacterEncoding(String defaultCharacterEncoding)
public void setEnableAssertions(boolean enabled)
public void setEnvironment(Map environmentVariables)
public Test setExcludes(Iterable excludes)
excludes
- The patterns list
public void setExecutable(Object executable)
public void setForkEvery(Long forkEvery)
forkEvery
- The maximum number of test classes. Use null or 0 to specify no maximum.
public void setIgnoreFailures(boolean ignoreFailures)
public Test setIncludes(Iterable includes)
includes
- The patterns list
public void setJvmArgs(Iterable arguments)
public void setMaxHeapSize(String heapSize)
public void setMaxParallelForks(int maxParallelForks)
maxParallelForks
- The maximum number of forked test processes.
public void setMinHeapSize(String heapSize)
public void setScanForTestClasses(boolean scanForTestClasses)
public void setSystemProperties(Map properties)
public void setTestClassesDir(File testClassesDir)
testClassesDir
- The root folder
@Option(option = "tests", description = "Sets test class or method name to be included, '*' is supported.") @Incubating public Test setTestNameIncludePattern(String testNamePattern)
@Deprecated public void setTestReport(boolean testReport)
@Deprecated public void setTestReportDir(File testReportDir)
testReportDir
- The root folder
@Deprecated public void setTestResultsDir(File testResultsDir)
testResultsDir
- The root folder
public void setTestSrcDirs(List testSrcDir)
public void setWorkingDir(Object dir)
public Test systemProperties(Map properties)
public Test systemProperty(String name, Object value)
public TestFramework testFramework(Closure testFrameworkConfigure)
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 closure
public void useJUnit()
To configure TestNG 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.
public Test workingDir(Object dir)
Gradle API 1.12