Class Test
- All Implemented Interfaces:
- 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>
The sample below shows various configuration options.
 plugins {
     id("java-library") // 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 SummaryNested classes/interfaces inherited from interface org.gradle.api.TaskTask.Namer
- 
Field SummaryFields inherited from interface org.gradle.api.TaskTASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbootstrapClasspath(Object... classpath) Adds the given values to the end of the bootstrap classpath for the process.copyTo(JavaForkOptions target) Copies these options to the given options.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> Creates test executer.protected org.gradle.api.internal.tasks.testing.JvmTestExecutionSpecCreates test execution specification.voiddebugOptions(Action<JavaDebugOptions> action) Configures Java Debug Wire Protocol properties for the process.environment(String name, Object value) Adds an environment variable to the environment for this process.environment(Map<String, ?> environmentVariables) Adds some environment variables to the environment for this process.Adds an exclude spec.Adds exclude patterns for the files in the test classes directory (e.g.Adds exclude patterns for the files in the test classes directory (e.g.exclude(Spec<FileTreeElement> excludeSpec) Adds an exclude spec.executable(Object executable) Sets the name of the executable to use.voidvoidfilter(Action<TestFilter> action) Executes the action against theAbstractTestTask.getFilter().protected org.gradle.internal.actor.ActorFactoryReturns the full set of arguments to use to launch the JVM for the process.Returns the bootstrap classpath to use for the process.Returns the classes files to scan for test classes.Returns the classpath to use to execute the tests.booleangetDebug()Determines whether debugging is enabled for the test process.Returns the Java Debug Wire Protocol properties for the process.Returns the default character encoding to use.Indicates if this task will skip individual test execution.booleanReturns true if assertions are enabled for the process.The environment variables to use for the process.Returns the exclude patterns for test execution.Returns the name of the executable to use.booleanIndicates if this task will fail on the first failed testlongReturns the maximum number of test classes to execute in a forked test process.protected org.gradle.process.internal.JavaForkOptionsFactoryReturns the include patterns for test execution.Configures the java executable to be used to run the tests.protected org.gradle.internal.jvm.JavaModuleDetectorprotected JavaToolchainServiceReturns the version of Java used to run the tests based on theJavaLauncherspecified bygetJavaLauncher(), or the executable specified bygetExecutable()if theJavaLauncheris not present.Returns the extra arguments to use to launch the JVM for the process.Command line argument providers for the java process to fork.Returns the maximum heap size for the process, if any.intReturns the maximum number of test processes to start in parallel.Returns the minimum heap size for the process, if any.Returns the module path handling of this test task.protected org.gradle.api.internal.classpath.ModuleRegistryReturns the reasons for no matching test error.protected ObjectFactoryReturns test framework specific options.protected org.gradle.api.tasks.util.internal.PatternSetFactoryprotected org.gradle.process.internal.worker.WorkerProcessFactoryprotected org.gradle.api.internal.provider.PropertyFactoryprotected ProviderFactoryprotected FileCollectionReturns the classpath to use to execute the tests.Returns the system properties which will be used for the process.Returns the directories for the compiled test sources.org.gradle.api.internal.tasks.testing.TestFrameworkProperty<org.gradle.api.internal.tasks.testing.TestFramework> Returns the configuredTestFramework.Returns the working directory for the process.Adds an include spec.Adds include patterns for the files in the test classes directory (e.g.Adds include patterns for the files in the test classes directory (e.g.include(Spec<FileTreeElement> includeSpec) Adds an include spec.booleanSpecifies whether test classes should be detected.Adds some arguments to use to launch the JVM for the process.Adds some arguments to use to launch the JVM for the process.Configures test framework specific options.options(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.setExcludes(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.voidsetForkEvery(Long forkEvery) Deprecated.setIncludes(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 test processes to start 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.setTestNameIncludePatterns(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.systemProperties(Map<String, ?> properties) Adds some system properties to use for the process.systemProperty(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 JUnit4 should be used to discover and execute the tests.voidSpecifies that JUnit4 should be used to discover and execute the tests with additional configuration.voiduseJUnit(Action<? super JUnitOptions> testFrameworkConfigure) Specifies that JUnit4 should be used to discover and execute the tests with additional configuration.voidSpecifies that JUnit Platform should be used to discover and execute the tests.voiduseJUnitPlatform(Action<? super JUnitPlatformOptions> testFrameworkConfigure) Specifies that JUnit Platform should be used to discover and execute the tests with additional configuration.voidSpecifies that TestNG should be used to discover and execute the tests.voidSpecifies that TestNG should be used to discover and execute the tests with additional configuration.voiduseTestNG(Action<? super TestNGOptions> testFrameworkConfigure) Specifies that TestNG should be used to discover and execute the tests with additional configuration.workingDir(Object dir) Sets the working directory for the process.Methods inherited from class org.gradle.api.tasks.testing.AbstractTestTaskaddTestListener, 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, testLoggingMethods inherited from class org.gradle.api.internal.ConventionTaskconventionMapping, conventionMapping, getConventionMappingMethods inherited from class org.gradle.api.DefaultTaskcompareTo, 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, usesServiceMethods inherited from class org.gradle.api.internal.AbstractTaskacceptServiceReferences, appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjectsMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.TaskdoNotTrackState, getConvention, notCompatibleWithConfigurationCache
- 
Constructor Details- 
Testpublic Test()
 
- 
- 
Method Details- 
getWorkingDirReturns the working directory for the process. Defaults to the project directory.- Specified by:
- getWorkingDirin interface- ProcessForkOptions
- Returns:
- The working directory. Never returns null.
 
- 
setWorkingDirSets the working directory for the process.- Specified by:
- setWorkingDirin interface- ProcessForkOptions
- Parameters:
- dir- The working directory. Must not be null.
 
- 
setWorkingDirSets the working directory for the process. The supplied argument is evaluated as perProject.file(Object).- Specified by:
- setWorkingDirin interface- ProcessForkOptions
- Parameters:
- dir- The working directory. Must not be null.
 
- 
workingDirSets the working directory for the process. The supplied argument is evaluated as perProject.file(Object).- Specified by:
- workingDirin interface- ProcessForkOptions
- Parameters:
- dir- The working directory. Must not be null.
- Returns:
- this
 
- 
getJavaVersionReturns the version of Java used to run the tests based on theJavaLauncherspecified bygetJavaLauncher(), or the executable specified bygetExecutable()if theJavaLauncheris not present.- Since:
- 3.3
 
- 
getExecutableReturns the name of the executable to use.- Specified by:
- getExecutablein interface- ProcessForkOptions
- Returns:
- The executable.
 
- 
executableSets the name of the executable to use.- Specified by:
- executablein interface- ProcessForkOptions
- Parameters:
- executable- The executable. Must not be null.
- Returns:
- this
 
- 
setExecutableSets the name of the executable to use.- Specified by:
- setExecutablein interface- ProcessForkOptions
- Parameters:
- executable- The executable. Must not be null.
 
- 
setExecutableSets the name of the executable to use.- Specified by:
- setExecutablein interface- ProcessForkOptions
- Parameters:
- executable- The executable. Must not be null.
 
- 
getSystemPropertiesReturns the system properties which will be used for the process.- Specified by:
- getSystemPropertiesin interface- JavaForkOptions
- Returns:
- The system properties. Returns an empty map when there are no system properties.
 
- 
setSystemPropertiesSets the system properties to use for the process.- Specified by:
- setSystemPropertiesin interface- JavaForkOptions
- Parameters:
- properties- The system properties. Must not be null.
 
- 
systemPropertiesAdds some system properties to use for the process.- Specified by:
- systemPropertiesin interface- JavaForkOptions
- Parameters:
- properties- The system properties. Must not be null.
- Returns:
- this
 
- 
systemPropertyAdds a system property to use for the process.- Specified by:
- systemPropertyin interface- JavaForkOptions
- Parameters:
- name- The name of the property
- value- The value for the property. May be null.
- Returns:
- this
 
- 
getBootstrapClasspathReturns 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 interface- JavaForkOptions
- Returns:
- The bootstrap classpath. Never returns null.
 
- 
setBootstrapClasspathSets 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 interface- JavaForkOptions
- Parameters:
- classpath- The classpath. Must not be null. Can be empty.
 
- 
bootstrapClasspathAdds the given values to the end of the bootstrap classpath for the process.- Specified by:
- bootstrapClasspathin interface- JavaForkOptions
- Parameters:
- classpath- The classpath.
- Returns:
- this
 
- 
getMinHeapSizeReturns the minimum heap size for the process, if any.- Specified by:
- getMinHeapSizein interface- JavaForkOptions
- Returns:
- The minimum heap size. Returns null if the default minimum heap size should be used.
 
- 
getDefaultCharacterEncodingReturns the default character encoding to use.- Specified by:
- getDefaultCharacterEncodingin interface- JavaForkOptions
- Returns:
- The default character encoding. Returns null if the default character encoding of this JVMshould be used.
 
- 
setDefaultCharacterEncodingSets 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 interface- JavaForkOptions
- Parameters:
- defaultCharacterEncoding- The default character encoding. Use null to use- this JVM's default charset
 
- 
setMinHeapSizeSets the minimum heap size for the process. Supports the units megabytes (e.g. "512m") and gigabytes (e.g. "1g").- Specified by:
- setMinHeapSizein interface- JavaForkOptions
- Parameters:
- heapSize- The minimum heap size. Use null for the default minimum heap size.
 
- 
getMaxHeapSizeReturns the maximum heap size for the process, if any.- Specified by:
- getMaxHeapSizein interface- JavaForkOptions
- Returns:
- The maximum heap size. Returns null if the default maximum heap size should be used.
 
- 
setMaxHeapSizeSets the maximum heap size for the process. Supports the units megabytes (e.g. "512m") and gigabytes (e.g. "1g").- Specified by:
- setMaxHeapSizein interface- JavaForkOptions
- Parameters:
- heapSize- The heap size. Use null for the default maximum heap size.
 
- 
getJvmArgsReturns 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 interface- JavaForkOptions
- Returns:
- The immutable list of arguments. Returns an empty list if there are no arguments.
 
- 
getJvmArgumentProvidersCommand line argument providers for the java process to fork.- Specified by:
- getJvmArgumentProvidersin interface- JavaForkOptions
 
- 
setJvmArgsSets the extra arguments to use to launch the JVM for the process. System properties and minimum/maximum heap size are updated.- Specified by:
- setJvmArgsin interface- JavaForkOptions
- Parameters:
- arguments- The arguments. Must not be null.
 
- 
setJvmArgsSets the extra arguments to use to launch the JVM for the process. System properties and minimum/maximum heap size are updated.- Specified by:
- setJvmArgsin interface- JavaForkOptions
- Parameters:
- arguments- The arguments. Must not be null.
 
- 
jvmArgsAdds some arguments to use to launch the JVM for the process.- Specified by:
- jvmArgsin interface- JavaForkOptions
- Parameters:
- arguments- The arguments. Must not be null.
- Returns:
- this
 
- 
jvmArgsAdds some arguments to use to launch the JVM for the process.- Specified by:
- jvmArgsin interface- JavaForkOptions
- Parameters:
- arguments- The arguments.
- Returns:
- this
 
- 
getEnableAssertionspublic boolean getEnableAssertions()Returns true if assertions are enabled for the process.- Specified by:
- getEnableAssertionsin interface- JavaForkOptions
- Returns:
- true if assertions are enabled, false if disabled
 
- 
setEnableAssertionspublic void setEnableAssertions(boolean enabled) Enable or disable assertions for the process.- Specified by:
- setEnableAssertionsin interface- JavaForkOptions
- Parameters:
- enabled- true to enable assertions, false to disable.
 
- 
getDebugpublic 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:
- getDebugin interface- JavaForkOptions
- Returns:
- true when debugging is enabled, false to disable.
 
- 
setDebugpublic 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:
- setDebugin interface- JavaForkOptions
- Parameters:
- enabled- true to enable debugging, false to disable.
 
- 
getDebugOptionsReturns 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:
- getDebugOptionsin interface- JavaForkOptions
 
- 
debugOptionsConfigures 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:
- debugOptionsin interface- JavaForkOptions
- Parameters:
- action- the Java debug configuration
 
- 
setFailFastpublic void setFailFast(boolean failFast) Enables fail fast behavior causing the task to fail on the first failed test.
- 
getFailFastpublic boolean getFailFast()Indicates if this task will fail on the first failed test- Returns:
- whether this task will fail on the first failed test
 
- 
getDryRunIndicates 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
 
- 
getAllJvmArgsReturns 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 interface- JavaForkOptions
- Returns:
- The immutable list of arguments. Returns an empty list if there are no arguments.
 
- 
setAllJvmArgsSets 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 interface- JavaForkOptions
- Parameters:
- arguments- The arguments. Must not be null.
 
- 
setAllJvmArgsSets 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 interface- JavaForkOptions
- Parameters:
- arguments- The arguments. Must not be null.
 
- 
getEnvironmentThe environment variables to use for the process. Defaults to the environment of this process.- Specified by:
- getEnvironmentin interface- ProcessForkOptions
- Returns:
- The environment. Returns an empty map when there are no environment variables.
 
- 
environmentAdds some environment variables to the environment for this process.- Specified by:
- environmentin interface- ProcessForkOptions
- Parameters:
- environmentVariables- The environment variables. Must not be null.
- Returns:
- this
 
- 
environmentAdds an environment variable to the environment for this process.- Specified by:
- environmentin interface- ProcessForkOptions
- Parameters:
- name- The name of the variable.
- value- The value for the variable. Must not be null.
- Returns:
- this
 
- 
setEnvironmentSets the environment variable to use for the process.- Specified by:
- setEnvironmentin interface- ProcessForkOptions
- Parameters:
- environmentVariables- The environment variables. Must not be null.
 
- 
copyToCopies these options to the given target options.- Specified by:
- copyToin interface- ProcessForkOptions
- Parameters:
- target- The target options
- Returns:
- this
 
- 
copyToCopies these options to the given options.- Specified by:
- copyToin interface- JavaForkOptions
- Parameters:
- target- The target options.
- Returns:
- this
 
- 
getModularityReturns the module path handling of this test task.- Since:
- 6.4
 
- 
createTestExecutionSpecprotected org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec createTestExecutionSpec()Creates test execution specification. For internal use only.- Specified by:
- createTestExecutionSpecin class- AbstractTestTask
- Since:
- 4.4
 
- 
executeTestspublic void executeTests()- Overrides:
- executeTestsin class- AbstractTestTask
 
- 
createTestExecuterprotected 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 class- AbstractTestTask
 
- 
getNoMatchingTestErrorReasonsDescription copied from class:AbstractTestTaskReturns the reasons for no matching test error.- Overrides:
- getNoMatchingTestErrorReasonsin class- AbstractTestTask
 
- 
includeAdds include patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
- includein interface- PatternFilterable
- Parameters:
- includes- a vararg list of include patterns
- Returns:
- this
- See Also:
 
- 
includeAdds include patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
- includein interface- PatternFilterable
- Parameters:
- includes- a Iterable providing more include patterns
- Returns:
- this
- See Also:
 
- 
includeAdds 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 interface- PatternFilterable
- Parameters:
- includeSpec- the spec to add
- Returns:
- this
- See Also:
 
- 
includeAdds 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 interface- PatternFilterable
- Parameters:
- includeSpec- the spec to add
- Returns:
- this
- See Also:
 
- 
excludeAdds exclude patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
- excludein interface- PatternFilterable
- Parameters:
- excludes- a vararg list of exclude patterns
- Returns:
- this
- See Also:
 
- 
excludeAdds exclude patterns for the files in the test classes directory (e.g. '**/*Test.class')).- Specified by:
- excludein interface- PatternFilterable
- Parameters:
- excludes- a Iterable providing new exclude patterns
- Returns:
- this
- See Also:
 
- 
excludeAdds 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 interface- PatternFilterable
- Parameters:
- excludeSpec- the spec to add
- Returns:
- this
- See Also:
 
- 
excludeAdds 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 interface- PatternFilterable
- Parameters:
- excludeSpec- the spec to add
- Returns:
- this
- See Also:
 
- 
setTestNameIncludePatternsSets 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 class- AbstractTestTask
 
- 
getTestClassesDirsReturns the directories for the compiled test sources.- Returns:
- All test class directories to be used.
- Since:
- 4.0
 
- 
setTestClassesDirsSets 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
 
- 
getIncludesReturns the include patterns for test execution.- Specified by:
- getIncludesin interface- PatternFilterable
- Returns:
- The include patterns. Returns an empty set when there are no include patterns.
- See Also:
 
- 
setIncludesSets the include patterns for test execution.- Specified by:
- setIncludesin interface- PatternFilterable
- Parameters:
- includes- The patterns list
- Returns:
- this
- See Also:
 
- 
getExcludesReturns the exclude patterns for test execution.- Specified by:
- getExcludesin interface- PatternFilterable
- Returns:
- The exclude patterns. Returns an empty set when there are no exclude patterns.
- See Also:
 
- 
setExcludesSets the exclude patterns for test execution.- Specified by:
- setExcludesin interface- PatternFilterable
- Parameters:
- excludes- The patterns list
- Returns:
- this
- See Also:
 
- 
getTestFrameworkPropertyReturns the configuredTestFramework.- Since:
- 7.3
 
- 
getTestFramework
- 
testFramework
- 
getOptionsReturns test framework specific options. Make sure to calluseJUnit(),useJUnitPlatform()oruseTestNG()before using this method.- Returns:
- The test framework options.
 
- 
optionspublic TestFrameworkOptions options(@DelegatesTo(TestFrameworkOptions.class) Closure testFrameworkConfigure) Configures test framework specific options.When a Testtask 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.
 
- 
optionsConfigures test framework specific options.When a Testtask 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
 
- 
useJUnitpublic void useJUnit()Specifies that JUnit4 should be used to discover and execute the tests.- See Also:
 
- 
useJUnitSpecifies 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.
 
- 
useJUnitSpecifies 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
 
- 
useJUnitPlatformpublic 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:
 
- 
useJUnitPlatformSpecifies 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
 
- 
useTestNGpublic void useTestNG()Specifies that TestNG should be used to discover and execute the tests.- See Also:
 
- 
useTestNGSpecifies 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.
 
- 
useTestNGSpecifies 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
 
- 
getStableClasspathReturns the classpath to use to execute the tests.- Since:
- 6.6
 
- 
getClasspathReturns the classpath to use to execute the tests.
- 
setClasspath
- 
isScanForTestClassesSpecifies 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.
- 
setScanForTestClassespublic void setScanForTestClasses(boolean scanForTestClasses) 
- 
getForkEveryReturns 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 1means that a new test process is started for every test class. This is very expensive.
- A value of Nmeans that a new test process is started afterNtest classes.
 - Returns:
- The maximum number of test classes to execute in a test process. Returns 0 when there is no maximum.
 
- A value of 
- 
setForkEverypublic 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
 
- 
setForkEveryDeprecated.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.
 
- 
getMaxParallelForksReturns the maximum number of test processes to start in parallel.By default, Gradle executes a single test class at a time. - A value of 1means to only execute a single test class in a single test process at a time. This is the default.
- A value of Nmeans that up toNtest processes will be started to execute test classes. This can improve test execution time by running multiple test classes in parallel.
 Testtasks.- Returns:
- The maximum number of forked test processes.
 
- A value of 
- 
setMaxParallelForkspublic 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 Testtasks 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.
 
- 
filterExecutes the action against theAbstractTestTask.getFilter().- Parameters:
- action- configuration of the test filter
- Since:
- 1.10
 
- 
getJavaLauncherConfigures the java executable to be used to run the tests.- Since:
- 6.7
 
- 
getObjectFactory
- 
getPropertyFactory@Inject protected org.gradle.api.internal.provider.PropertyFactory getPropertyFactory()
- 
getJavaToolchainService
- 
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.api.tasks.util.internal.PatternSetFactory 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()
 
- 
setForkEvery(long)instead.