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:
java.lang.Comparable<Task>
,org.gradle.api.internal.DynamicObjectAware
,org.gradle.api.internal.IConventionAware
,org.gradle.api.internal.TaskInternal
,Named
,ExtensionAware
,Reporting<TestTaskReports>
,Task
,PatternFilterable
,VerificationTask
,JavaForkOptions
,ProcessForkOptions
,Configurable<Task>
@NonNullApi @CacheableTask public abstract 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.
plugins { id 'java' // adds 'test' task } test { // discover and execute JUnit4-based tests useJUnit() // discover and execute TestNG-based tests useTestNG() // discover and execute JUnit Platform-based tests 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 // skip an actual test execution dryRun = 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 Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Test
bootstrapClasspath(java.lang.Object... classpath)
Adds the given values to the end of the bootstrap classpath for the process.Test
copyTo(JavaForkOptions target)
Copies these options to the given options.Test
copyTo(ProcessForkOptions target)
Copies these options to the given target options.protected org.gradle.api.internal.tasks.testing.TestExecuter<org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec>
createTestExecuter()
Creates test executer.protected org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec
createTestExecutionSpec()
Creates test execution specification.void
debugOptions(Action<JavaDebugOptions> action)
Configures Java Debug Wire Protocol properties for the process.Test
environment(java.lang.String name, java.lang.Object value)
Adds an environment variable to the environment for this process.Test
environment(java.util.Map<java.lang.String,?> environmentVariables)
Adds some environment variables to the environment for this process.Test
exclude(Closure excludeSpec)
Adds an exclude spec.Test
exclude(java.lang.Iterable<java.lang.String> excludes)
Adds exclude patterns for the files in the test classes directory (e.g.Test
exclude(java.lang.String... excludes)
Adds exclude patterns for the files in the test classes directory (e.g.Test
exclude(Spec<FileTreeElement> excludeSpec)
Adds an exclude spec.Test
executable(java.lang.Object executable)
Sets the name of the executable to use.void
executeTests()
void
filter(Action<TestFilter> action)
Executes the action against theAbstractTestTask.getFilter()
.protected org.gradle.internal.actor.ActorFactory
getActorFactory()
java.util.List<java.lang.String>
getAllJvmArgs()
Returns the full set of arguments to use to launch the JVM for the process.FileCollection
getBootstrapClasspath()
Returns the bootstrap classpath to use for the process.FileTree
getCandidateClassFiles()
Returns the classes files to scan for test classes.FileCollection
getClasspath()
Returns the classpath to use to execute the tests.boolean
getDebug()
Determines whether debugging is enabled for the test process.JavaDebugOptions
getDebugOptions()
Returns the Java Debug Wire Protocol properties for the process.java.lang.String
getDefaultCharacterEncoding()
Returns the default character encoding to use.abstract Property<java.lang.Boolean>
getDryRun()
Indicates if this task will skip individual test execution.boolean
getEnableAssertions()
Returns true if assertions are enabled for the process.java.util.Map<java.lang.String,java.lang.Object>
getEnvironment()
The environment variables to use for the process.java.util.Set<java.lang.String>
getExcludes()
Returns the exclude patterns for test execution.java.lang.String
getExecutable()
Returns the name of the executable to use.boolean
getFailFast()
Indicates if this task will fail on the first failed testlong
getForkEvery()
Returns the maximum number of test classes to execute in a forked test process.protected org.gradle.process.internal.JavaForkOptionsFactory
getForkOptionsFactory()
java.util.Set<java.lang.String>
getIncludes()
Returns the include patterns for test execution.Property<JavaLauncher>
getJavaLauncher()
Configures the java executable to be used to run the tests.protected org.gradle.internal.jvm.JavaModuleDetector
getJavaModuleDetector()
protected JavaToolchainService
getJavaToolchainService()
JavaVersion
getJavaVersion()
Returns the version of Java used to run the tests based on theJavaLauncher
specified bygetJavaLauncher()
, or the executable specified bygetExecutable()
if theJavaLauncher
is not present.java.util.List<java.lang.String>
getJvmArgs()
Returns the extra arguments to use to launch the JVM for the process.java.util.List<CommandLineArgumentProvider>
getJvmArgumentProviders()
Command line argument providers for the java process to fork.java.lang.String
getMaxHeapSize()
Returns the maximum heap size for the process, if any.int
getMaxParallelForks()
Returns the maximum number of test processes to start in parallel.java.lang.String
getMinHeapSize()
Returns the minimum heap size for the process, if any.ModularitySpec
getModularity()
Returns the module path handling of this test task.protected org.gradle.api.internal.classpath.ModuleRegistry
getModuleRegistry()
protected java.util.List<java.lang.String>
getNoMatchingTestErrorReasons()
Returns the reasons for no matching test error.protected ObjectFactory
getObjectFactory()
TestFrameworkOptions
getOptions()
Returns test framework specific options.protected org.gradle.internal.Factory<PatternSet>
getPatternSetFactory()
protected org.gradle.process.internal.worker.WorkerProcessFactory
getProcessBuilderFactory()
protected ProviderFactory
getProviderFactory()
protected FileCollection
getStableClasspath()
Returns the classpath to use to execute the tests.java.util.Map<java.lang.String,java.lang.Object>
getSystemProperties()
Returns the system properties which will be used for the process.FileCollection
getTestClassesDirs()
Returns the directories for the compiled test sources.org.gradle.api.internal.tasks.testing.TestFramework
getTestFramework()
Property<org.gradle.api.internal.tasks.testing.TestFramework>
getTestFrameworkProperty()
Returns the configuredTestFramework
.java.io.File
getWorkingDir()
Returns the working directory for the process.Test
include(Closure includeSpec)
Adds an include spec.Test
include(java.lang.Iterable<java.lang.String> includes)
Adds include patterns for the files in the test classes directory (e.g.Test
include(java.lang.String... includes)
Adds include patterns for the files in the test classes directory (e.g.Test
include(Spec<FileTreeElement> includeSpec)
Adds an include spec.boolean
isScanForTestClasses()
Specifies whether test classes should be detected.Test
jvmArgs(java.lang.Iterable<?> arguments)
Adds some arguments to use to launch the JVM for the process.Test
jvmArgs(java.lang.Object... arguments)
Adds some arguments to use to launch the JVM for the process.TestFrameworkOptions
options(Closure testFrameworkConfigure)
Configures test framework specific options.TestFrameworkOptions
options(Action<? super TestFrameworkOptions> testFrameworkConfigure)
Configures test framework specific options.void
setAllJvmArgs(java.lang.Iterable<?> arguments)
Sets the full set of arguments to use to launch the JVM for the process.void
setAllJvmArgs(java.util.List<java.lang.String> arguments)
Sets the full set of arguments to use to launch the JVM for the process.void
setBootstrapClasspath(FileCollection classpath)
Sets the bootstrap classpath to use for the process.void
setClasspath(FileCollection classpath)
void
setDebug(boolean enabled)
Enable or disable debugging for the process.void
setDefaultCharacterEncoding(java.lang.String defaultCharacterEncoding)
Sets the default character encoding to use.void
setEnableAssertions(boolean enabled)
Enable or disable assertions for the process.void
setEnvironment(java.util.Map<java.lang.String,?> environmentVariables)
Sets the environment variable to use for the process.Test
setExcludes(java.lang.Iterable<java.lang.String> excludes)
Sets the exclude patterns for test execution.void
setExecutable(java.lang.Object executable)
Sets the name of the executable to use.void
setExecutable(java.lang.String executable)
Sets the name of the executable to use.void
setFailFast(boolean failFast)
Enables fail fast behavior causing the task to fail on the first failed test.void
setForkEvery(long forkEvery)
Sets the maximum number of test classes to execute in a forked test process.void
setForkEvery(java.lang.Long forkEvery)
Deprecated.UsesetForkEvery(long)
instead.Test
setIncludes(java.lang.Iterable<java.lang.String> includes)
Sets the include patterns for test execution.void
setJvmArgs(java.lang.Iterable<?> arguments)
Sets the extra arguments to use to launch the JVM for the process.void
setJvmArgs(java.util.List<java.lang.String> arguments)
Sets the extra arguments to use to launch the JVM for the process.void
setMaxHeapSize(java.lang.String heapSize)
Sets the maximum heap size for the process.void
setMaxParallelForks(int maxParallelForks)
Sets the maximum number of test processes to start in parallel.void
setMinHeapSize(java.lang.String heapSize)
Sets the minimum heap size for the process.void
setScanForTestClasses(boolean scanForTestClasses)
void
setSystemProperties(java.util.Map<java.lang.String,?> properties)
Sets the system properties to use for the process.void
setTestClassesDirs(FileCollection testClassesDirs)
Sets the directories to scan for compiled test sources.Test
setTestNameIncludePatterns(java.util.List<java.lang.String> testNamePattern)
Sets the test name patterns to be included in execution.void
setWorkingDir(java.io.File dir)
Sets the working directory for the process.void
setWorkingDir(java.lang.Object dir)
Sets the working directory for the process.Test
systemProperties(java.util.Map<java.lang.String,?> properties)
Adds some system properties to use for the process.Test
systemProperty(java.lang.String name, java.lang.Object value)
Adds a system property to use for the process.org.gradle.api.internal.tasks.testing.TestFramework
testFramework(Closure testFrameworkConfigure)
void
useJUnit()
Specifies that JUnit4 should be used to discover and execute the tests.void
useJUnit(Closure testFrameworkConfigure)
Specifies that JUnit4 should be used to discover and execute the tests with additional configuration.void
useJUnit(Action<? super JUnitOptions> testFrameworkConfigure)
Specifies that JUnit4 should be used to discover and execute the tests with additional configuration.void
useJUnitPlatform()
Specifies that JUnit Platform should be used to discover and execute the tests.void
useJUnitPlatform(Action<? super JUnitPlatformOptions> testFrameworkConfigure)
Specifies that JUnit Platform should be used to discover and execute the tests with additional configuration.void
useTestNG()
Specifies that TestNG should be used to discover and execute the tests.void
useTestNG(Closure testFrameworkConfigure)
Specifies that TestNG should be used to discover and execute the tests with additional configuration.void
useTestNG(Action<? super TestNGOptions> testFrameworkConfigure)
Specifies that TestNG should be used to discover and execute the tests with additional configuration.Test
workingDir(java.lang.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, getBuildOperationExecutor, getBuildOperationRunner, getFileSystemOperations, getFilter, getHostnameLookup, getIgnoreFailures, getInstantiator, getListenerManager, getProgressLoggerFactory, getReports, getTestLogging, getTextOutputFactory, onOutput, removeTestListener, removeTestOutputListener, reports, reports, setIgnoreFailures, testLogging, testLogging
-
Methods inherited from class org.gradle.api.internal.ConventionTask
conventionMapping, conventionMapping, getConventionMapping
-
Methods inherited from class org.gradle.api.DefaultTask
compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService
-
Methods inherited from class org.gradle.api.internal.AbstractTask
acceptServiceReferences, appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjects
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.gradle.api.Task
doNotTrackState, getConvention, notCompatibleWithConfigurationCache
-
-
-
-
Method Detail
-
getWorkingDir
@Internal public java.io.File getWorkingDir()
Returns the working directory for the process. Defaults to the project directory.- Specified by:
getWorkingDir
in interfaceProcessForkOptions
- Returns:
- The working directory. Never returns null.
-
setWorkingDir
public void setWorkingDir(java.io.File dir)
Sets the working directory for the process.- Specified by:
setWorkingDir
in interfaceProcessForkOptions
- Parameters:
dir
- The working directory. Must not be null.
-
setWorkingDir
public void setWorkingDir(java.lang.Object dir)
Sets the working directory for the process. The supplied argument is evaluated as perProject.file(Object)
.- Specified by:
setWorkingDir
in interfaceProcessForkOptions
- Parameters:
dir
- The working directory. Must not be null.
-
workingDir
public Test workingDir(java.lang.Object dir)
Sets the working directory for the process. The supplied argument is evaluated as perProject.file(Object)
.- Specified by:
workingDir
in 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 theJavaLauncher
specified bygetJavaLauncher()
, or the executable specified bygetExecutable()
if theJavaLauncher
is not present.- Since:
- 3.3
-
getExecutable
@Internal public java.lang.String getExecutable()
Returns the name of the executable to use.- Specified by:
getExecutable
in interfaceProcessForkOptions
- Returns:
- The executable.
-
executable
public Test executable(java.lang.Object executable)
Sets the name of the executable to use.- Specified by:
executable
in interfaceProcessForkOptions
- Parameters:
executable
- The executable. Must not be null.- Returns:
- this
-
setExecutable
public void setExecutable(java.lang.String executable)
Sets the name of the executable to use.- Specified by:
setExecutable
in interfaceProcessForkOptions
- Parameters:
executable
- The executable. Must not be null.
-
setExecutable
public void setExecutable(java.lang.Object executable)
Sets the name of the executable to use.- Specified by:
setExecutable
in interfaceProcessForkOptions
- Parameters:
executable
- The executable. Must not be null.
-
getSystemProperties
public java.util.Map<java.lang.String,java.lang.Object> getSystemProperties()
Returns the system properties which will be used for the process.- Specified by:
getSystemProperties
in interfaceJavaForkOptions
- Returns:
- The system properties. Returns an empty map when there are no system properties.
-
setSystemProperties
public void setSystemProperties(java.util.Map<java.lang.String,?> properties)
Sets the system properties to use for the process.- Specified by:
setSystemProperties
in interfaceJavaForkOptions
- Parameters:
properties
- The system properties. Must not be null.
-
systemProperties
public Test systemProperties(java.util.Map<java.lang.String,?> properties)
Adds some system properties to use for the process.- Specified by:
systemProperties
in interfaceJavaForkOptions
- Parameters:
properties
- The system properties. Must not be null.- Returns:
- this
-
systemProperty
public Test systemProperty(java.lang.String name, java.lang.Object value)
Adds a system property to use for the process.- Specified by:
systemProperty
in 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:
getBootstrapClasspath
in 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:
setBootstrapClasspath
in interfaceJavaForkOptions
- Parameters:
classpath
- The classpath. Must not be null. Can be empty.
-
bootstrapClasspath
public Test bootstrapClasspath(java.lang.Object... classpath)
Adds the given values to the end of the bootstrap classpath for the process.- Specified by:
bootstrapClasspath
in interfaceJavaForkOptions
- Parameters:
classpath
- The classpath.- Returns:
- this
-
getMinHeapSize
public java.lang.String getMinHeapSize()
Returns the minimum heap size for the process, if any.- Specified by:
getMinHeapSize
in interfaceJavaForkOptions
- Returns:
- The minimum heap size. Returns null if the default minimum heap size should be used.
-
getDefaultCharacterEncoding
public java.lang.String getDefaultCharacterEncoding()
Returns the default character encoding to use.- Specified by:
getDefaultCharacterEncoding
in interfaceJavaForkOptions
- Returns:
- The default character encoding. Returns null if the
default character encoding of this JVM
should be used.
-
setDefaultCharacterEncoding
public void setDefaultCharacterEncoding(java.lang.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.encoding
property). For JVMs where this is the case, setting thefile.encoding
property 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:
setDefaultCharacterEncoding
in interfaceJavaForkOptions
- Parameters:
defaultCharacterEncoding
- The default character encoding. Use null to usethis JVM's default charset
-
setMinHeapSize
public void setMinHeapSize(java.lang.String heapSize)
Sets the minimum heap size for the process. Supports the units megabytes (e.g. "512m") and gigabytes (e.g. "1g").- Specified by:
setMinHeapSize
in interfaceJavaForkOptions
- Parameters:
heapSize
- The minimum heap size. Use null for the default minimum heap size.
-
getMaxHeapSize
public java.lang.String getMaxHeapSize()
Returns the maximum heap size for the process, if any.- Specified by:
getMaxHeapSize
in interfaceJavaForkOptions
- Returns:
- The maximum heap size. Returns null if the default maximum heap size should be used.
-
setMaxHeapSize
public void setMaxHeapSize(java.lang.String heapSize)
Sets the maximum heap size for the process. Supports the units megabytes (e.g. "512m") and gigabytes (e.g. "1g").- Specified by:
setMaxHeapSize
in interfaceJavaForkOptions
- Parameters:
heapSize
- The heap size. Use null for the default maximum heap size.
-
getJvmArgs
public java.util.List<java.lang.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:
getJvmArgs
in interfaceJavaForkOptions
- Returns:
- The immutable list of arguments. Returns an empty list if there are no arguments.
-
getJvmArgumentProviders
public java.util.List<CommandLineArgumentProvider> getJvmArgumentProviders()
Command line argument providers for the java process to fork.- Specified by:
getJvmArgumentProviders
in interfaceJavaForkOptions
-
setJvmArgs
public void setJvmArgs(java.util.List<java.lang.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:
setJvmArgs
in interfaceJavaForkOptions
- Parameters:
arguments
- The arguments. Must not be null.
-
setJvmArgs
public void setJvmArgs(java.lang.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:
setJvmArgs
in interfaceJavaForkOptions
- Parameters:
arguments
- The arguments. Must not be null.
-
jvmArgs
public Test jvmArgs(java.lang.Iterable<?> arguments)
Adds some arguments to use to launch the JVM for the process.- Specified by:
jvmArgs
in interfaceJavaForkOptions
- Parameters:
arguments
- The arguments. Must not be null.- Returns:
- this
-
jvmArgs
public Test jvmArgs(java.lang.Object... arguments)
Adds some arguments to use to launch the JVM for the process.- Specified by:
jvmArgs
in interfaceJavaForkOptions
- Parameters:
arguments
- The arguments.- Returns:
- this
-
getEnableAssertions
public boolean getEnableAssertions()
Returns true if assertions are enabled for the process.- Specified by:
getEnableAssertions
in 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:
setEnableAssertions
in 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()
.Since Gradle 5.6, you can configure the port and other Java debug properties via
JavaForkOptions.debugOptions(Action)
.- Specified by:
getDebug
in 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.The debug properties (e.g. the port number) can be configured in
JavaForkOptions.debugOptions(Action)
.- Specified by:
setDebug
in interfaceJavaForkOptions
- Parameters:
enabled
- true to enable debugging, false to disable.
-
getDebugOptions
public JavaDebugOptions getDebugOptions()
Returns the Java Debug Wire Protocol properties for the process. If enabled then the-agentlib:jdwp=...
will be appended to the JVM arguments with the configuration from the parameter.- Specified by:
getDebugOptions
in interfaceJavaForkOptions
-
debugOptions
public void debugOptions(Action<JavaDebugOptions> action)
Configures Java Debug Wire Protocol properties for the process. IfJavaForkOptions.setDebug(boolean)
is enabled then the-agentlib:jdwp=...
will be appended to the JVM arguments with the configuration from the parameter.- Specified by:
debugOptions
in interfaceJavaForkOptions
- Parameters:
action
- the Java debug configuration
-
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
-
getDryRun
@Incubating @Input public abstract Property<java.lang.Boolean> getDryRun()
Indicates if this task will skip individual test execution.For JUnit 4 and 5, this will report tests that would have executed as skipped. For TestNG, this will report tests that would have executed as passed.
Only versions of TestNG which support native dry-running are supported, i.e. TestNG 6.14 or later.
- Returns:
- property for whether this task will skip individual test execution
- Since:
- 8.3
-
getAllJvmArgs
public java.util.List<java.lang.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:
getAllJvmArgs
in interfaceJavaForkOptions
- Returns:
- The immutable list of arguments. Returns an empty list if there are no arguments.
-
setAllJvmArgs
public void setAllJvmArgs(java.util.List<java.lang.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:
setAllJvmArgs
in interfaceJavaForkOptions
- Parameters:
arguments
- The arguments. Must not be null.
-
setAllJvmArgs
public void setAllJvmArgs(java.lang.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:
setAllJvmArgs
in interfaceJavaForkOptions
- Parameters:
arguments
- The arguments. Must not be null.
-
getEnvironment
@Internal public java.util.Map<java.lang.String,java.lang.Object> getEnvironment()
The environment variables to use for the process. Defaults to the environment of this process.- Specified by:
getEnvironment
in interfaceProcessForkOptions
- Returns:
- The environment. Returns an empty map when there are no environment variables.
-
environment
public Test environment(java.util.Map<java.lang.String,?> environmentVariables)
Adds some environment variables to the environment for this process.- Specified by:
environment
in interfaceProcessForkOptions
- Parameters:
environmentVariables
- The environment variables. Must not be null.- Returns:
- this
-
environment
public Test environment(java.lang.String name, java.lang.Object value)
Adds an environment variable to the environment for this process.- Specified by:
environment
in interfaceProcessForkOptions
- Parameters:
name
- The name of the variable.value
- The value for the variable. Must not be null.- Returns:
- this
-
setEnvironment
public void setEnvironment(java.util.Map<java.lang.String,?> environmentVariables)
Sets the environment variable to use for the process.- Specified by:
setEnvironment
in 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:
copyTo
in interfaceProcessForkOptions
- Parameters:
target
- The target options- Returns:
- this
-
copyTo
public Test copyTo(JavaForkOptions target)
Copies these options to the given options.- Specified by:
copyTo
in interfaceJavaForkOptions
- Parameters:
target
- The target options.- Returns:
- this
-
getModularity
public ModularitySpec getModularity()
Returns the module path handling of this test task.- Since:
- 6.4
-
createTestExecutionSpec
protected org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec createTestExecutionSpec()
Creates test execution specification. For internal use only.- Specified by:
createTestExecutionSpec
in classAbstractTestTask
- Since:
- 4.4
-
executeTests
public void executeTests()
- Overrides:
executeTests
in classAbstractTestTask
-
createTestExecuter
protected org.gradle.api.internal.tasks.testing.TestExecuter<org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec> createTestExecuter()
Description copied from class:AbstractTestTask
Creates test executer. For internal use only.- Specified by:
createTestExecuter
in classAbstractTestTask
-
getNoMatchingTestErrorReasons
protected java.util.List<java.lang.String> getNoMatchingTestErrorReasons()
Description copied from class:AbstractTestTask
Returns the reasons for no matching test error.- Overrides:
getNoMatchingTestErrorReasons
in classAbstractTestTask
-
include
public Test include(java.lang.String... includes)
Adds include patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
include
in interfacePatternFilterable
- Parameters:
includes
- a vararg list of include patterns- Returns:
- this
- See Also:
setIncludes(Iterable)
-
include
public Test include(java.lang.Iterable<java.lang.String> includes)
Adds include patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
include
in 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:
include
in 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 aFileTreeElement
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.- Specified by:
include
in interfacePatternFilterable
- Parameters:
includeSpec
- the spec to add- Returns:
- this
- See Also:
Pattern Format
-
exclude
public Test exclude(java.lang.String... excludes)
Adds exclude patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
exclude
in interfacePatternFilterable
- Parameters:
excludes
- a vararg list of exclude patterns- Returns:
- this
- See Also:
setExcludes(Iterable)
-
exclude
public Test exclude(java.lang.Iterable<java.lang.String> excludes)
Adds exclude patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
exclude
in 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:
exclude
in 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 aFileTreeElement
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.- Specified by:
exclude
in interfacePatternFilterable
- Parameters:
excludeSpec
- the spec to add- Returns:
- this
- See Also:
FileTreeElement
-
setTestNameIncludePatterns
public Test setTestNameIncludePatterns(java.util.List<java.lang.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:
setTestNameIncludePatterns
in 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:plugins { id '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 java.util.Set<java.lang.String> getIncludes()
Returns the include patterns for test execution.- Specified by:
getIncludes
in interfacePatternFilterable
- Returns:
- The include patterns. Returns an empty set when there are no include patterns.
- See Also:
include(String...)
-
setIncludes
public Test setIncludes(java.lang.Iterable<java.lang.String> includes)
Sets the include patterns for test execution.- Specified by:
setIncludes
in interfacePatternFilterable
- Parameters:
includes
- The patterns list- Returns:
- this
- See Also:
include(String...)
-
getExcludes
@Internal public java.util.Set<java.lang.String> getExcludes()
Returns the exclude patterns for test execution.- Specified by:
getExcludes
in interfacePatternFilterable
- Returns:
- The exclude patterns. Returns an empty set when there are no exclude patterns.
- See Also:
exclude(String...)
-
setExcludes
public Test setExcludes(java.lang.Iterable<java.lang.String> excludes)
Sets the exclude patterns for test execution.- Specified by:
setExcludes
in interfacePatternFilterable
- Parameters:
excludes
- The patterns list- Returns:
- this
- See Also:
exclude(String...)
-
getTestFrameworkProperty
public Property<org.gradle.api.internal.tasks.testing.TestFramework> getTestFrameworkProperty()
Returns the configuredTestFramework
.- Since:
- 7.3
-
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(@DelegatesTo(TestFrameworkOptions.class) Closure testFrameworkConfigure)
Configures test framework specific options.When a
Test
task is created outside of Test Suites, you should calluseJUnit()
,useJUnitPlatform()
oruseTestNG()
before using this method. If no test framework has been set, the task will assume JUnit4.- Returns:
- The test framework options.
-
options
public TestFrameworkOptions options(Action<? super TestFrameworkOptions> testFrameworkConfigure)
Configures test framework specific options.When a
Test
task is created outside of Test Suites, you should calluseJUnit()
,useJUnitPlatform()
oruseTestNG()
before using this method. If no test framework has been set, the task will assume JUnit4.- Returns:
- The test framework options.
- Since:
- 3.5
-
useJUnit
public void useJUnit()
Specifies that JUnit4 should be used to discover and execute the tests.- See Also:
Configure JUnit4 specific options.
-
useJUnit
public void useJUnit(@Nullable @DelegatesTo(JUnitOptions.class) Closure testFrameworkConfigure)
Specifies that JUnit4 should be used to discover and execute the tests with additional configuration.The supplied action configures an instance of
JUnit4 specific options
.- Parameters:
testFrameworkConfigure
- A closure used to configure JUnit4 options.
-
useJUnit
public void useJUnit(Action<? super JUnitOptions> testFrameworkConfigure)
Specifies that JUnit4 should be used to discover and execute the tests with additional configuration.The supplied action configures an instance of
JUnit4 specific options
.- Parameters:
testFrameworkConfigure
- An action used to configure JUnit4 options.- Since:
- 3.5
-
useJUnitPlatform
public void useJUnitPlatform()
Specifies that JUnit Platform should be used to discover and execute the tests.Use this option if your tests use JUnit Jupiter/JUnit5.
JUnit Platform supports multiple test engines, which allows other testing frameworks to be built on top of it. You may need to use this option even if you are not using JUnit directly.
- Since:
- 4.6
- See Also:
Configure JUnit Platform specific options.
-
useJUnitPlatform
public void useJUnitPlatform(Action<? super JUnitPlatformOptions> testFrameworkConfigure)
Specifies that JUnit Platform should be used to discover and execute the tests with additional configuration.Use this option if your tests use JUnit Jupiter/JUnit5.
JUnit Platform supports multiple test engines, which allows other testing frameworks to be built on top of it. You may need to use this option even if you are not using JUnit directly.
The supplied action configures an instance of
JUnit Platform specific options
.- Parameters:
testFrameworkConfigure
- A closure used to configure JUnit platform options.- Since:
- 4.6
-
useTestNG
public void useTestNG()
Specifies that TestNG should be used to discover and execute the tests.- See Also:
Configure TestNG specific options.
-
useTestNG
public void useTestNG(@DelegatesTo(TestNGOptions.class) Closure testFrameworkConfigure)
Specifies that TestNG should be used to discover and execute the tests with additional configuration.The supplied action configures an instance of
TestNG specific options
.- Parameters:
testFrameworkConfigure
- A closure used to configure TestNG options.
-
useTestNG
public void useTestNG(Action<? super TestNGOptions> testFrameworkConfigure)
Specifies that TestNG should be used to discover and execute the tests with additional configuration.The supplied action configures an instance of
TestNG specific options
.- Parameters:
testFrameworkConfigure
- An action used to configure TestNG options.- Since:
- 3.5
-
getStableClasspath
@Classpath protected FileCollection getStableClasspath()
Returns the classpath to use to execute the tests.- Since:
- 6.6
-
getClasspath
@Internal("captured by stableClasspath") 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. Whentrue
the classes which match the include and exclude patterns are scanned for test classes, and any found are executed. Whenfalse
the 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.By default, Gradle automatically uses a separate JVM when executing tests.
- A value of
0
(no limit) means to reuse the test process for all test classes. This is the default. - A value of
1
means that a new test process is started for every test class. This is very expensive. - A value of
N
means that a new test process is started afterN
test classes.
- Returns:
- The maximum number of test classes to execute in a test process. Returns 0 when there is no maximum.
- A value of
-
setForkEvery
public void setForkEvery(long forkEvery)
Sets the maximum number of test classes to execute in a forked test process.By default, Gradle automatically uses a separate JVM when executing tests, so changing this property is usually not necessary.
- Parameters:
forkEvery
- The maximum number of test classes. Use 0 to specify no maximum.- Since:
- 8.1
-
setForkEvery
@Deprecated public void setForkEvery(@Nullable java.lang.Long forkEvery)
Deprecated.UsesetForkEvery(long)
instead.Sets the maximum number of test classes to execute in a forked test process.By default, Gradle automatically uses a separate JVM when executing tests, so changing this property is usually not necessary.
- 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 test processes to start in parallel.By default, Gradle executes a single test class at a time.
- A value of
1
means to only execute a single test class in a single test process at a time. This is the default. - A value of
N
means that up toN
test processes will be started to execute test classes. This can improve test execution time by running multiple test classes in parallel.
Test
tasks.- Returns:
- The maximum number of forked test processes.
- A value of
-
setMaxParallelForks
public void setMaxParallelForks(int maxParallelForks)
Sets the maximum number of test processes to start in parallel.By default, Gradle executes a single test class at a time but allows multiple
Test
tasks to run in parallel.- Parameters:
maxParallelForks
- The maximum number of forked test processes. Use 1 to disable parallel test execution for this task.
-
getCandidateClassFiles
@InputFiles @SkipWhenEmpty @IgnoreEmptyDirectories @PathSensitive(RELATIVE) 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
-
getJavaLauncher
public Property<JavaLauncher> getJavaLauncher()
Configures the java executable to be used to run the tests.- Since:
- 6.7
-
getObjectFactory
@Inject protected ObjectFactory getObjectFactory()
-
getJavaToolchainService
@Inject protected JavaToolchainService getJavaToolchainService()
-
getProviderFactory
@Inject protected ProviderFactory getProviderFactory()
-
getActorFactory
@Inject protected org.gradle.internal.actor.ActorFactory getActorFactory()
-
getProcessBuilderFactory
@Inject protected org.gradle.process.internal.worker.WorkerProcessFactory getProcessBuilderFactory()
-
getPatternSetFactory
@Inject protected org.gradle.internal.Factory<PatternSet> getPatternSetFactory()
-
getForkOptionsFactory
@Inject protected org.gradle.process.internal.JavaForkOptionsFactory getForkOptionsFactory()
-
getModuleRegistry
@Inject protected org.gradle.api.internal.classpath.ModuleRegistry getModuleRegistry()
-
getJavaModuleDetector
@Inject protected org.gradle.internal.jvm.JavaModuleDetector getJavaModuleDetector()
-
-