Class Test
- java.lang.Object
-
- org.gradle.api.internal.AbstractTask
-
- org.gradle.api.DefaultTask
-
- org.gradle.api.internal.ConventionTask
-
- org.gradle.api.tasks.testing.AbstractTestTask
-
- org.gradle.api.tasks.testing.Test
-
- All Implemented Interfaces:
Comparable<Task>,org.gradle.api.internal.DynamicObjectAware,org.gradle.api.internal.IConventionAware,org.gradle.api.internal.TaskInternal,ExtensionAware,Reporting<TestTaskReports>,Task,PatternFilterable,VerificationTask,JavaForkOptions,ProcessForkOptions,org.gradle.util.Configurable<Task>
@NonNullApi @CacheableTask public class Test extends AbstractTestTask implements JavaForkOptions, PatternFilterable
Executes JUnit (3.8.x, 4.x or 5.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() // enable JUnit Platform (a.k.a. JUnit 5) support useJUnitPlatform() // 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) } // Fail the 'test' task on the first test failure failFast = true // 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.gradle.api.Task
Task.Namer
-
-
Field Summary
-
Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
-
-
Constructor Summary
Constructors Constructor Description Test()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TestbootstrapClasspath(Object... classpath)Adds the given values to the end of the bootstrap classpath for the process.TestcopyTo(JavaForkOptions target)Copies these options to the given options.TestcopyTo(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.JvmTestExecutionSpeccreateTestExecutionSpec()Creates test execution specification.Testenvironment(String name, Object value)Adds an environment variable to the environment for this process.Testenvironment(Map<String,?> environmentVariables)Adds some environment variables to the environment for this process.Testexclude(Closure excludeSpec)Adds an exclude spec.Testexclude(Iterable<String> excludes)Adds exclude patterns for the files in the test classes directory (e.g.Testexclude(String... excludes)Adds exclude patterns for the files in the test classes directory (e.g.Testexclude(Spec<FileTreeElement> excludeSpec)Adds an exclude spec.Testexecutable(Object executable)Sets the name of the executable to use.voidexecuteTests()voidfilter(Action<TestFilter> action)Executes the action against theAbstractTestTask.getFilter().protected org.gradle.internal.actor.ActorFactorygetActorFactory()List<String>getAllJvmArgs()Returns the full set of arguments to use to launch the JVM for the process.FileCollectiongetBootstrapClasspath()Returns the bootstrap classpath to use for the process.FileTreegetCandidateClassFiles()Returns the classes files to scan for test classes.protected org.gradle.api.internal.initialization.loadercache.ClassLoaderCachegetClassLoaderCache()FileCollectiongetClasspath()Returns the classpath to use to execute the tests.booleangetDebug()Determines whether debugging is enabled for the test process.StringgetDefaultCharacterEncoding()Returns the default character encoding to use.booleangetEnableAssertions()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.StringgetExecutable()Returns the name of the executable to use.booleangetFailFast()Indicates if this task will fail on the first failed testprotected org.gradle.api.internal.file.FileResolvergetFileResolver()longgetForkEvery()Returns the maximum number of test classes to execute in a forked test process.Set<String>getIncludes()Returns the include patterns for test execution.JavaVersiongetJavaVersion()Returns the version of Java used to run the tests based on the executable specified bygetExecutable().List<String>getJvmArgs()Returns the extra arguments to use to launch the JVM for the process.List<CommandLineArgumentProvider>getJvmArgumentProviders()Command line argument providers for the java process to fork.StringgetMaxHeapSize()Returns the maximum heap size for the process, if any.intgetMaxParallelForks()Returns the maximum number of forked test processes to execute in parallel.StringgetMinHeapSize()Returns the minimum heap size for the process, if any.protected org.gradle.api.internal.classpath.ModuleRegistrygetModuleRegistry()protected List<String>getNoMatchingTestErrorReasons()Returns the reasons for no matching test error.TestFrameworkOptionsgetOptions()Returns test framework specific options.protected org.gradle.process.internal.worker.WorkerProcessFactorygetProcessBuilderFactory()Map<String,Object>getSystemProperties()Returns the system properties which will be used for the process.FileCollectiongetTestClassesDirs()Returns the directories for the compiled test sources.org.gradle.api.internal.tasks.testing.TestFrameworkgetTestFramework()FilegetWorkingDir()Returns the working directory for the process.Testinclude(Closure includeSpec)Adds an include spec.Testinclude(Iterable<String> includes)Adds include patterns for the files in the test classes directory (e.g.Testinclude(String... includes)Adds include patterns for the files in the test classes directory (e.g.Testinclude(Spec<FileTreeElement> includeSpec)Adds an include spec.booleanisScanForTestClasses()Specifies whether test classes should be detected.TestjvmArgs(Iterable<?> arguments)Adds some arguments to use to launch the JVM for the process.TestjvmArgs(Object... arguments)Adds some arguments to use to launch the JVM for the process.TestFrameworkOptionsoptions(Closure testFrameworkConfigure)Configures test framework specific options.TestFrameworkOptionsoptions(Action<? super TestFrameworkOptions> testFrameworkConfigure)Configures test framework specific options.voidsetAllJvmArgs(Iterable<?> arguments)Sets the full set of arguments to use to launch the JVM for the process.voidsetAllJvmArgs(List<String> arguments)Sets the full set of arguments to use to launch the JVM for the process.voidsetBootstrapClasspath(FileCollection classpath)Sets the bootstrap classpath to use for the process.voidsetClasspath(FileCollection classpath)voidsetDebug(boolean enabled)Enable or disable debugging for the process.voidsetDefaultCharacterEncoding(String defaultCharacterEncoding)Sets the default character encoding to use.voidsetEnableAssertions(boolean enabled)Enable or disable assertions for the process.voidsetEnvironment(Map<String,?> environmentVariables)Sets the environment variable to use for the process.TestsetExcludes(Iterable<String> excludes)Sets the exclude patterns for test execution.voidsetExecutable(Object executable)Sets the name of the executable to use.voidsetExecutable(String executable)Sets the name of the executable to use.voidsetFailFast(boolean failFast)Enables fail fast behavior causing the task to fail on the first failed test.voidsetForkEvery(Long forkEvery)Sets the maximum number of test classes to execute in a forked test process.TestsetIncludes(Iterable<String> includes)Sets the include patterns for test execution.voidsetJvmArgs(Iterable<?> arguments)Sets the extra arguments to use to launch the JVM for the process.voidsetJvmArgs(List<String> arguments)Sets the extra arguments to use to launch the JVM for the process.voidsetMaxHeapSize(String heapSize)Sets the maximum heap size for the process.voidsetMaxParallelForks(int maxParallelForks)Sets the maximum number of forked test processes to execute in parallel.voidsetMinHeapSize(String heapSize)Sets the minimum heap size for the process.voidsetScanForTestClasses(boolean scanForTestClasses)voidsetSystemProperties(Map<String,?> properties)Sets the system properties to use for the process.voidsetTestClassesDirs(FileCollection testClassesDirs)Sets the directories to scan for compiled test sources.TestsetTestNameIncludePatterns(List<String> testNamePattern)Sets the test name patterns to be included in execution.voidsetWorkingDir(File dir)Sets the working directory for the process.voidsetWorkingDir(Object dir)Sets the working directory for the process.TestsystemProperties(Map<String,?> properties)Adds some system properties to use for the process.TestsystemProperty(String name, Object value)Adds a system property to use for the process.org.gradle.api.internal.tasks.testing.TestFrameworktestFramework(Closure testFrameworkConfigure)voiduseJUnit()Specifies that JUnit should be used to execute the tests.voiduseJUnit(Closure testFrameworkConfigure)Specifies that JUnit should be used to execute the tests, configuring JUnit specific options.voiduseJUnit(Action<? super JUnitOptions> testFrameworkConfigure)Specifies that JUnit should be used to execute the tests, configuring JUnit specific options.voiduseJUnitPlatform()Specifies that JUnit Platform (a.k.a.voiduseJUnitPlatform(Action<? super JUnitPlatformOptions> testFrameworkConfigure)Specifies that JUnit Platform (a.k.a.voiduseTestNG()Specifies that TestNG should be used to execute the tests.voiduseTestNG(Closure testFrameworkConfigure)Specifies that TestNG should be used to execute the tests, configuring TestNG specific options.voiduseTestNG(Action<? super TestNGOptions> testFrameworkConfigure)Specifies that TestNG should be used to execute the tests, configuring TestNG specific options.TestworkingDir(Object dir)Sets the working directory for the process.-
Methods inherited from class org.gradle.api.tasks.testing.AbstractTestTask
addTestListener, addTestOutputListener, afterSuite, afterTest, beforeSuite, beforeTest, getBinaryResultsDirectory, getBinResultsDir, getBuildOperationExecutor, getCallbackActionDecorator, getFilter, getIgnoreFailures, getInetAddressFactory, getInstantiator, getListenerManager, getProgressLoggerFactory, getReports, getTestLogging, getTextOutputFactory, onOutput, removeTestListener, removeTestOutputListener, reports, reports, setBinResultsDir, setIgnoreFailures, testLogging, testLogging
-
Methods inherited from class org.gradle.api.internal.ConventionTask
conventionMapping, conventionMapping, getConventionMapping
-
Methods inherited from class org.gradle.api.DefaultTask
newInputDirectory, newInputFile, newOutputDirectory, newOutputFile
-
Methods inherited from class org.gradle.api.internal.AbstractTask
appendParallelSafeAction, compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getAsDynamicObject, getConvention, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getIdentityPath, getImpliesSubProjects, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOnlyIf, getOutputs, getPath, getProject, getServices, getShouldRunAfter, getStandardOutputCapture, getState, getTaskActions, getTaskDependencies, getTaskIdentity, getTemporaryDir, getTemporaryDirFactory, getTimeout, hasProperty, hasTaskActions, injectIntoNewInstance, isEnabled, isHasCustomActions, mustRunAfter, onlyIf, onlyIf, prependParallelSafeAction, property, replaceLogger, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setImpliesSubProjects, setMustRunAfter, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, toString
-
-
-
-
Method Detail
-
getActorFactory
@Inject protected org.gradle.internal.actor.ActorFactory getActorFactory()
-
getClassLoaderCache
@Inject protected org.gradle.api.internal.initialization.loadercache.ClassLoaderCache getClassLoaderCache()
-
getProcessBuilderFactory
@Inject protected org.gradle.process.internal.worker.WorkerProcessFactory getProcessBuilderFactory()
-
getFileResolver
@Inject protected org.gradle.api.internal.file.FileResolver getFileResolver()
-
getModuleRegistry
@Inject protected org.gradle.api.internal.classpath.ModuleRegistry getModuleRegistry()
-
getWorkingDir
@Internal public File getWorkingDir()
Returns the working directory for the process. Defaults to the project directory.- Specified by:
getWorkingDirin interfaceProcessForkOptions- Returns:
- The working directory. Never returns null.
-
setWorkingDir
public void setWorkingDir(File dir)
Sets the working directory for the process.- Specified by:
setWorkingDirin interfaceProcessForkOptions- Parameters:
dir- The working directory. Must not be null.
-
setWorkingDir
public void setWorkingDir(Object dir)
Sets the working directory for the process. The supplied argument is evaluated as perProject.file(Object).- Specified by:
setWorkingDirin interfaceProcessForkOptions- Parameters:
dir- The working directory. Must not be null.
-
workingDir
public Test workingDir(Object dir)
Sets the working directory for the process. The supplied argument is evaluated as perProject.file(Object).- Specified by:
workingDirin interfaceProcessForkOptions- Parameters:
dir- The working directory. Must not be null.- Returns:
- this
-
getJavaVersion
@Input public JavaVersion getJavaVersion()
Returns the version of Java used to run the tests based on the executable specified bygetExecutable().- Since:
- 3.3
-
getExecutable
@Internal public String getExecutable()
Returns the name of the executable to use.- Specified by:
getExecutablein interfaceProcessForkOptions- Returns:
- The executable.
-
executable
public Test executable(Object executable)
Sets the name of the executable to use.- Specified by:
executablein interfaceProcessForkOptions- Parameters:
executable- The executable. Must not be null.- Returns:
- this
-
setExecutable
public void setExecutable(String executable)
Sets the name of the executable to use.- Specified by:
setExecutablein interfaceProcessForkOptions- Parameters:
executable- The executable. Must not be null.
-
setExecutable
public void setExecutable(Object executable)
Sets the name of the executable to use.- Specified by:
setExecutablein interfaceProcessForkOptions- Parameters:
executable- The executable. Must not be null.
-
getSystemProperties
public Map<String,Object> getSystemProperties()
Returns the system properties which will be used for the process.- Specified by:
getSystemPropertiesin interfaceJavaForkOptions- Returns:
- The system properties. Returns an empty map when there are no system properties.
-
setSystemProperties
public void setSystemProperties(Map<String,?> properties)
Sets the system properties to use for the process.- Specified by:
setSystemPropertiesin interfaceJavaForkOptions- Parameters:
properties- The system properties. Must not be null.
-
systemProperties
public Test systemProperties(Map<String,?> properties)
Adds some system properties to use for the process.- Specified by:
systemPropertiesin interfaceJavaForkOptions- Parameters:
properties- The system properties. Must not be null.- Returns:
- this
-
systemProperty
public Test systemProperty(String name, Object value)
Adds a system property to use for the process.- Specified by:
systemPropertyin interfaceJavaForkOptions- Parameters:
name- The name of the propertyvalue- The value for the property. May be null.- Returns:
- this
-
getBootstrapClasspath
public FileCollection getBootstrapClasspath()
Returns the bootstrap classpath to use for the process. The default bootstrap classpath for the JVM is used when this classpath is empty.- Specified by:
getBootstrapClasspathin interfaceJavaForkOptions- Returns:
- The bootstrap classpath. Never returns null.
-
setBootstrapClasspath
public void setBootstrapClasspath(FileCollection classpath)
Sets the bootstrap classpath to use for the process. Set to an empty classpath to use the default bootstrap classpath for the specified JVM.- Specified by:
setBootstrapClasspathin interfaceJavaForkOptions- Parameters:
classpath- The classpath. Must not be null. Can be empty.
-
bootstrapClasspath
public Test bootstrapClasspath(Object... classpath)
Adds the given values to the end of the bootstrap classpath for the process.- Specified by:
bootstrapClasspathin interfaceJavaForkOptions- Parameters:
classpath- The classpath.- Returns:
- this
-
getMinHeapSize
public String getMinHeapSize()
Returns the minimum heap size for the process, if any.- Specified by:
getMinHeapSizein interfaceJavaForkOptions- Returns:
- The minimum heap size. Returns null if the default minimum heap size should be used.
-
getDefaultCharacterEncoding
public String getDefaultCharacterEncoding()
Returns the default character encoding to use.- Specified by:
getDefaultCharacterEncodingin interfaceJavaForkOptions- Returns:
- The default character encoding. Returns null if the
default character encoding of this JVMshould be used.
-
setDefaultCharacterEncoding
public void setDefaultCharacterEncoding(String defaultCharacterEncoding)
Sets the default character encoding to use. Note: Many JVM implementations support the setting of this attribute via system property on startup (namely, thefile.encodingproperty). For JVMs where this is the case, setting thefile.encodingproperty viaJavaForkOptions.setSystemProperties(java.util.Map)or similar will have no effect as this value will be overridden by the value specified byJavaForkOptions.getDefaultCharacterEncoding().- Specified by:
setDefaultCharacterEncodingin interfaceJavaForkOptions- Parameters:
defaultCharacterEncoding- The default character encoding. Use null to usethis JVM's default charset
-
setMinHeapSize
public void setMinHeapSize(String heapSize)
Sets the minimum heap size for the process.- Specified by:
setMinHeapSizein interfaceJavaForkOptions- Parameters:
heapSize- The minimum heap size. Use null for the default minimum heap size.
-
getMaxHeapSize
public String getMaxHeapSize()
Returns the maximum heap size for the process, if any.- Specified by:
getMaxHeapSizein interfaceJavaForkOptions- Returns:
- The maximum heap size. Returns null if the default maximum heap size should be used.
-
setMaxHeapSize
public void setMaxHeapSize(String heapSize)
Sets the maximum heap size for the process.- Specified by:
setMaxHeapSizein interfaceJavaForkOptions- Parameters:
heapSize- The heap size. Use null for the default maximum heap size.
-
getJvmArgs
public List<String> getJvmArgs()
Returns the extra arguments to use to launch the JVM for the process. Does not include system properties and the minimum/maximum heap size.- Specified by:
getJvmArgsin interfaceJavaForkOptions- Returns:
- The arguments. Returns an empty list if there are no arguments.
-
getJvmArgumentProviders
public List<CommandLineArgumentProvider> getJvmArgumentProviders()
Command line argument providers for the java process to fork.- Specified by:
getJvmArgumentProvidersin interfaceJavaForkOptions
-
setJvmArgs
public void setJvmArgs(List<String> arguments)
Sets the extra arguments to use to launch the JVM for the process. System properties and minimum/maximum heap size are updated.- Specified by:
setJvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments. Must not be null.
-
setJvmArgs
public void setJvmArgs(Iterable<?> arguments)
Sets the extra arguments to use to launch the JVM for the process. System properties and minimum/maximum heap size are updated.- Specified by:
setJvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments. Must not be null.
-
jvmArgs
public Test jvmArgs(Iterable<?> arguments)
Adds some arguments to use to launch the JVM for the process.- Specified by:
jvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments. Must not be null.- Returns:
- this
-
jvmArgs
public Test jvmArgs(Object... arguments)
Adds some arguments to use to launch the JVM for the process.- Specified by:
jvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments.- Returns:
- this
-
getEnableAssertions
public boolean getEnableAssertions()
Returns true if assertions are enabled for the process.- Specified by:
getEnableAssertionsin interfaceJavaForkOptions- Returns:
- true if assertions are enabled, false if disabled
-
setEnableAssertions
public void setEnableAssertions(boolean enabled)
Enable or disable assertions for the process.- Specified by:
setEnableAssertionsin interfaceJavaForkOptions- Parameters:
enabled- true to enable assertions, false to disable.
-
getDebug
public boolean getDebug()
Determines whether debugging is enabled for the test process. When enabled —debug = true— the process is started in a suspended state, listening on port 5005. You should disable parallel test execution when debugging and you will need to reattach the debugger occasionally if you use a non-zero value forgetForkEvery().- Specified by:
getDebugin interfaceJavaForkOptions- Returns:
- true when debugging is enabled, false to disable.
-
setDebug
public void setDebug(boolean enabled)
Enable or disable debugging for the process. When enabled, the process is started suspended and listening on port 5005.- Specified by:
setDebugin interfaceJavaForkOptions- Parameters:
enabled- true to enable debugging, false to disable.
-
setFailFast
public void setFailFast(boolean failFast)
Enables fail fast behavior causing the task to fail on the first failed test.
-
getFailFast
public boolean getFailFast()
Indicates if this task will fail on the first failed test- Returns:
- whether this task will fail on the first failed test
-
getAllJvmArgs
public List<String> getAllJvmArgs()
Returns the full set of arguments to use to launch the JVM for the process. This includes arguments to define system properties, the minimum/maximum heap size, and the bootstrap classpath.- Specified by:
getAllJvmArgsin interfaceJavaForkOptions- Returns:
- The arguments. Returns an empty list if there are no arguments.
-
setAllJvmArgs
public void setAllJvmArgs(List<String> arguments)
Sets the full set of arguments to use to launch the JVM for the process. Overwrites any previously set system properties, minimum/maximum heap size, assertions, and bootstrap classpath.- Specified by:
setAllJvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments. Must not be null.
-
setAllJvmArgs
public void setAllJvmArgs(Iterable<?> arguments)
Sets the full set of arguments to use to launch the JVM for the process. Overwrites any previously set system properties, minimum/maximum heap size, assertions, and bootstrap classpath.- Specified by:
setAllJvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments. Must not be null.
-
getEnvironment
@Internal public Map<String,Object> getEnvironment()
The environment variables to use for the process. Defaults to the environment of this process.- Specified by:
getEnvironmentin interfaceProcessForkOptions- Returns:
- The environment. Returns an empty map when there are no environment variables.
-
environment
public Test environment(Map<String,?> environmentVariables)
Adds some environment variables to the environment for this process.- Specified by:
environmentin interfaceProcessForkOptions- Parameters:
environmentVariables- The environment variables. Must not be null.- Returns:
- this
-
environment
public Test environment(String name, Object value)
Adds an environment variable to the environment for this process.- Specified by:
environmentin interfaceProcessForkOptions- Parameters:
name- The name of the variable.value- The value for the variable. Must not be null.- Returns:
- this
-
setEnvironment
public void setEnvironment(Map<String,?> environmentVariables)
Sets the environment variable to use for the process.- Specified by:
setEnvironmentin interfaceProcessForkOptions- Parameters:
environmentVariables- The environment variables. Must not be null.
-
copyTo
public Test copyTo(ProcessForkOptions target)
Copies these options to the given target options.- Specified by:
copyToin interfaceProcessForkOptions- Parameters:
target- The target options- Returns:
- this
-
copyTo
public Test copyTo(JavaForkOptions target)
Copies these options to the given options.- Specified by:
copyToin interfaceJavaForkOptions- Parameters:
target- The target options.- Returns:
- this
-
createTestExecutionSpec
protected org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec createTestExecutionSpec()
Creates test execution specification. For internal use only.- Specified by:
createTestExecutionSpecin classAbstractTestTask- Since:
- 4.4
-
executeTests
public void executeTests()
- Overrides:
executeTestsin classAbstractTestTask
-
createTestExecuter
protected org.gradle.api.internal.tasks.testing.TestExecuter<org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec> createTestExecuter()
Description copied from class:AbstractTestTaskCreates test executer. For internal use only.- Specified by:
createTestExecuterin classAbstractTestTask
-
getNoMatchingTestErrorReasons
protected List<String> getNoMatchingTestErrorReasons()
Description copied from class:AbstractTestTaskReturns the reasons for no matching test error.- Overrides:
getNoMatchingTestErrorReasonsin classAbstractTestTask
-
include
public Test include(String... includes)
Adds include patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
includein interfacePatternFilterable- Parameters:
includes- a vararg list of include patterns- Returns:
- this
- See Also:
setIncludes(Iterable)
-
include
public Test include(Iterable<String> includes)
Adds include patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
includein interfacePatternFilterable- Parameters:
includes- a Iterable providing more include patterns- Returns:
- this
- See Also:
setIncludes(Iterable)
-
include
public Test include(Spec<FileTreeElement> 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.- Specified by:
includein interfacePatternFilterable- Parameters:
includeSpec- the spec to add- Returns:
- this
- See Also:
Pattern Format
-
include
public Test include(Closure includeSpec)
Adds an include spec. This method may be called multiple times to append new specs. The given closure is passed aFileTreeElementas 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.- Specified by:
includein interfacePatternFilterable- Parameters:
includeSpec- the spec to add- Returns:
- this
- See Also:
Pattern Format
-
exclude
public Test exclude(String... excludes)
Adds exclude patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
excludein interfacePatternFilterable- Parameters:
excludes- a vararg list of exclude patterns- Returns:
- this
- See Also:
setExcludes(Iterable)
-
exclude
public Test exclude(Iterable<String> excludes)
Adds exclude patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
excludein interfacePatternFilterable- Parameters:
excludes- a Iterable providing new exclude patterns- Returns:
- this
- See Also:
setExcludes(Iterable)
-
exclude
public Test exclude(Spec<FileTreeElement> 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.- Specified by:
excludein interfacePatternFilterable- Parameters:
excludeSpec- the spec to add- Returns:
- this
- See Also:
Pattern Format
-
exclude
public Test exclude(Closure excludeSpec)
Adds an exclude spec. This method may be called multiple times to append new specs.The given closure is passed aFileTreeElementas 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.- Specified by:
excludein interfacePatternFilterable- Parameters:
excludeSpec- the spec to add- Returns:
- this
- See Also:
FileTreeElement
-
setTestNameIncludePatterns
public Test setTestNameIncludePatterns(List<String> testNamePattern)
Sets the test name patterns to be included in execution. Classes or method names are supported, wildcard '*' is supported. For more information see the user guide chapter on testing. For more information on supported patterns seeTestFilter- Overrides:
setTestNameIncludePatternsin classAbstractTestTask
-
getTestClassesDirs
@Internal public FileCollection getTestClassesDirs()
Returns the directories for the compiled test sources.- Returns:
- All test class directories to be used.
- Since:
- 4.0
-
setTestClassesDirs
public void setTestClassesDirs(FileCollection testClassesDirs)
Sets the directories to scan for compiled test sources. Typically, this would be configured to use the output of a source set: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 }- Parameters:
testClassesDirs- All test class directories to be used.- Since:
- 4.0
-
getIncludes
@Internal public Set<String> getIncludes()
Returns the include patterns for test execution.- Specified by:
getIncludesin interfacePatternFilterable- Returns:
- The include patterns. Returns an empty set when there are no include patterns.
- See Also:
include(String...)
-
setIncludes
public Test setIncludes(Iterable<String> includes)
Sets the include patterns for test execution.- Specified by:
setIncludesin interfacePatternFilterable- Parameters:
includes- The patterns list- Returns:
- this
- See Also:
include(String...)
-
getExcludes
@Internal public Set<String> getExcludes()
Returns the exclude patterns for test execution.- Specified by:
getExcludesin interfacePatternFilterable- Returns:
- The exclude patterns. Returns an empty set when there are no exclude patterns.
- See Also:
exclude(String...)
-
setExcludes
public Test setExcludes(Iterable<String> excludes)
Sets the exclude patterns for test execution.- Specified by:
setExcludesin interfacePatternFilterable- Parameters:
excludes- The patterns list- Returns:
- this
- See Also:
exclude(String...)
-
getTestFramework
@Internal public org.gradle.api.internal.tasks.testing.TestFramework getTestFramework()
-
testFramework
public org.gradle.api.internal.tasks.testing.TestFramework testFramework(@Nullable Closure testFrameworkConfigure)
-
getOptions
public TestFrameworkOptions getOptions()
Returns test framework specific options. Make sure to calluseJUnit(),useJUnitPlatform()oruseTestNG()before using this method.- Returns:
- The test framework options.
-
options
public TestFrameworkOptions options(Closure testFrameworkConfigure)
Configures test framework specific options. Make sure to calluseJUnit(),useJUnitPlatform()oruseTestNG()before using this method.- Returns:
- The test framework options.
-
options
public TestFrameworkOptions options(Action<? super TestFrameworkOptions> testFrameworkConfigure)
Configures test framework specific options. Make sure to calluseJUnit(),useJUnitPlatform()oruseTestNG()before using this method.- Returns:
- The test framework options.
- Since:
- 3.5
-
useJUnit
public void useJUnit()
Specifies that JUnit should be used to execute the tests.To configure JUnit specific options, see
useJUnit(groovy.lang.Closure).
-
useJUnit
public void useJUnit(@Nullable Closure testFrameworkConfigure)
Specifies that JUnit should be used to execute the tests, configuring JUnit specific options.The supplied closure configures an instance of
JUnitOptions, which can be used to configure how JUnit runs.- Parameters:
testFrameworkConfigure- A closure used to configure the JUnit options.
-
useJUnit
public void useJUnit(Action<? super JUnitOptions> testFrameworkConfigure)
Specifies that JUnit should be used to execute the tests, configuring JUnit specific options.The supplied action configures an instance of
JUnitOptions, which can be used to configure how JUnit runs.- Parameters:
testFrameworkConfigure- An action used to configure the JUnit options.- Since:
- 3.5
-
useJUnitPlatform
@Incubating public void useJUnitPlatform()
Specifies that JUnit Platform (a.k.a. JUnit 5) should be used to execute the tests.To configure JUnit platform specific options, see
useJUnitPlatform(Action).- Since:
- 4.6
-
useJUnitPlatform
@Incubating public void useJUnitPlatform(Action<? super JUnitPlatformOptions> testFrameworkConfigure)
Specifies that JUnit Platform (a.k.a. JUnit 5) should be used to execute the tests, configuring JUnit platform specific options.The supplied action configures an instance of
JUnitPlatformOptions, which can be used to configure how JUnit platform runs.- Parameters:
testFrameworkConfigure- An action used to configure the JUnit platform options.- Since:
- 4.6
-
useTestNG
public void useTestNG()
Specifies that TestNG should be used to execute the tests.To configure TestNG specific options, see
useTestNG(Closure).
-
useTestNG
public void useTestNG(Closure testFrameworkConfigure)
Specifies that TestNG should be used to execute the tests, configuring TestNG specific options.The supplied closure configures an instance of
TestNGOptions, which can be used to configure how TestNG runs.- Parameters:
testFrameworkConfigure- A closure used to configure the TestNG options.
-
useTestNG
public void useTestNG(Action<? super TestNGOptions> testFrameworkConfigure)
Specifies that TestNG should be used to execute the tests, configuring TestNG specific options.The supplied action configures an instance of
TestNGOptions, which can be used to configure how TestNG runs.- Parameters:
testFrameworkConfigure- An action used to configure the TestNG options.- Since:
- 3.5
-
getClasspath
@Classpath public FileCollection getClasspath()
Returns the classpath to use to execute the tests.
-
setClasspath
public void setClasspath(FileCollection classpath)
-
isScanForTestClasses
@Input public boolean isScanForTestClasses()
Specifies whether test classes should be detected. Whentruethe classes which match the include and exclude patterns are scanned for test classes, and any found are executed. Whenfalsethe classes which match the include and exclude patterns are executed.
-
setScanForTestClasses
public void setScanForTestClasses(boolean scanForTestClasses)
-
getForkEvery
@Internal public long getForkEvery()
Returns 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).- Returns:
- The maximum number of test classes. Returns 0 when there is no maximum.
-
setForkEvery
public void setForkEvery(@Nullable Long forkEvery)
Sets the maximum number of test classes to execute in a forked test process. Use null or 0 to use no maximum.- Parameters:
forkEvery- The maximum number of test classes. Use null or 0 to specify no maximum.
-
getMaxParallelForks
@Internal public int getMaxParallelForks()
Returns the maximum number of forked test processes to execute in parallel. The default value is 1 (no parallel test execution). It cannot exceed the value of max-workers for the current build.- Returns:
- The maximum number of forked test processes.
-
setMaxParallelForks
public void setMaxParallelForks(int maxParallelForks)
Sets the maximum number of forked test processes to execute in parallel. Set to 1 to disable parallel test execution.- Parameters:
maxParallelForks- The maximum number of forked test processes.
-
getCandidateClassFiles
@PathSensitive(RELATIVE) @InputFiles @SkipWhenEmpty public FileTree getCandidateClassFiles()
Returns the classes files to scan for test classes.- Returns:
- The candidate class files.
-
filter
public void filter(Action<TestFilter> action)
Executes the action against theAbstractTestTask.getFilter().- Parameters:
action- configuration of the test filter- Since:
- 1.10
-
-