@NonNullApi @CacheableTask open class Test : AbstractTestTask, 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
Test() |
open fun bootstrapClasspath(vararg classpath: Any): Test
{@inheritDoc} |
|
open fun copyTo(target: ProcessForkOptions): Test open fun copyTo(target: JavaForkOptions): Test
{@inheritDoc} |
|
open fun environment(environmentVariables: MutableMap<String, *>): Test open fun environment(name: String, value: Any): Test
{@inheritDoc} |
|
open fun exclude(vararg excludes: String): Test open fun exclude(excludes: MutableIterable<String>): Test
Adds exclude patterns for the files in the test classes directory (e.g. '**/*Test.class')). open fun exclude(excludeSpec: Spec<FileTreeElement>): Test open fun exclude(excludeSpec: Closure<Any>): Test
{@inheritDoc} |
|
open fun executable(executable: Any): Test
{@inheritDoc} |
|
open fun executeTests(): Unit |
|
open fun filter(action: Action<TestFilter>): Unit
Executes the action against the |
|
open fun getAllJvmArgs(): MutableList<String>
{@inheritDoc} |
|
open fun getBootstrapClasspath(): FileCollection
{@inheritDoc} |
|
open fun getCandidateClassFiles(): FileTree
Returns the classes files to scan for test classes. |
|
open fun getClasspath(): FileCollection
Returns the classpath to use to execute the tests. |
|
open fun getDebug(): Boolean
{@inheritDoc} |
|
open fun getDefaultCharacterEncoding(): String
{@inheritDoc} |
|
open fun getEnableAssertions(): Boolean
{@inheritDoc} |
|
open fun getEnvironment(): MutableMap<String, Any>
{@inheritDoc} |
|
open fun getExcludes(): MutableSet<String>
Returns the exclude patterns for test execution. |
|
open fun getExecutable(): String
{@inheritDoc} |
|
open fun getFailFast(): Boolean
Indicates if this task will fail on the first failed test |
|
open fun getForkEvery(): Long
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). |
|
open fun getIncludes(): MutableSet<String>
Returns the include patterns for test execution. |
|
open fun getJavaVersion(): JavaVersion
Returns the version of Java used to run the tests based on the executable specified by |
|
open fun getJvmArgs(): MutableList<String>
{@inheritDoc} |
|
open fun getJvmArgumentProviders(): MutableList<CommandLineArgumentProvider>
{@inheritDoc} |
|
open fun getMaxHeapSize(): String
{@inheritDoc} |
|
open fun getMaxParallelForks(): Int
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. |
|
open fun getMinHeapSize(): String
{@inheritDoc} |
|
open fun getOptions(): TestFrameworkOptions
Returns test framework specific options. Make sure to call |
|
open fun getSystemProperties(): MutableMap<String, Any>
{@inheritDoc} |
|
open fun getTestClassesDir(): File
Returns the root folder for the compiled test sources. |
|
open fun getTestClassesDirs(): FileCollection
Returns the directories for the compiled test sources. |
|
open fun getTestFramework(): TestFramework |
|
open fun getWorkingDir(): File
{@inheritDoc} |
|
open fun include(vararg includes: String): Test open fun include(includes: MutableIterable<String>): Test
Adds include patterns for the files in the test classes directory (e.g. '**/*Test.class')). open fun include(includeSpec: Spec<FileTreeElement>): Test open fun include(includeSpec: Closure<Any>): Test
{@inheritDoc} |
|
open fun isScanForTestClasses(): Boolean
Specifies whether test classes should be detected. When |
|
open fun jvmArgs(arguments: MutableIterable<*>): Test open fun jvmArgs(vararg arguments: Any): Test
{@inheritDoc} |
|
open fun options(testFrameworkConfigure: Closure<Any>): TestFrameworkOptions open fun options(testFrameworkConfigure: Action<in TestFrameworkOptions>): TestFrameworkOptions
Configures test framework specific options. Make sure to call |
|
open fun setAllJvmArgs(arguments: MutableList<String>): Unit open fun setAllJvmArgs(arguments: MutableIterable<*>): Unit
{@inheritDoc} |
|
open fun setBootstrapClasspath(classpath: FileCollection): Unit
{@inheritDoc} |
|
open fun setClasspath(classpath: FileCollection): Unit |
|
open fun setDebug(enabled: Boolean): Unit
{@inheritDoc} |
|
open fun setDefaultCharacterEncoding(defaultCharacterEncoding: String): Unit
{@inheritDoc} |
|
open fun setEnableAssertions(enabled: Boolean): Unit
{@inheritDoc} |
|
open fun setEnvironment(environmentVariables: MutableMap<String, *>): Unit
{@inheritDoc} |
|
open fun setExcludes(excludes: MutableIterable<String>): Test
Sets the exclude patterns for test execution. |
|
open fun setExecutable(executable: String): Unit open fun setExecutable(executable: Any): Unit
{@inheritDoc} |
|
open fun setFailFast(failFast: Boolean): Unit
Enables fail fast behavior causing the task to fail on the first failed test. |
|
open fun setForkEvery(forkEvery: Long): Unit
Sets the maximum number of test classes to execute in a forked test process. Use null or 0 to use no maximum. |
|
open fun setIncludes(includes: MutableIterable<String>): Test
Sets the include patterns for test execution. |
|
open fun setJvmArgs(arguments: MutableList<String>): Unit open fun setJvmArgs(arguments: MutableIterable<*>): Unit
{@inheritDoc} |
|
open fun setMaxHeapSize(heapSize: String): Unit
{@inheritDoc} |
|
open fun setMaxParallelForks(maxParallelForks: Int): Unit
Sets the maximum number of forked test processes to execute in parallel. Set to 1 to disable parallel test execution. |
|
open fun setMinHeapSize(heapSize: String): Unit
{@inheritDoc} |
|
open fun setScanForTestClasses(scanForTestClasses: Boolean): Unit |
|
open fun setSystemProperties(properties: MutableMap<String, *>): Unit
{@inheritDoc} |
|
open fun setTestClassesDir(testClassesDir: File): Unit
Sets the root folder for the compiled test sources. |
|
open fun setTestClassesDirs(testClassesDirs: FileCollection): Unit
Sets the directories to scan for compiled test sources. Typically, this would be configured to use the output of a source set:
|
|
open fun setTestNameIncludePatterns(testNamePattern: MutableList<String>): Test
{@inheritDoc} |
|
open fun setWorkingDir(dir: File): Unit open fun setWorkingDir(dir: Any): Unit
{@inheritDoc} |
|
open fun systemProperties(properties: MutableMap<String, *>): Test
{@inheritDoc} |
|
open fun systemProperty(name: String, value: Any): Test
{@inheritDoc} |
|
open fun testFramework(testFrameworkConfigure: Closure<Any>): TestFramework |
|
open fun useJUnit(): Unit
Specifies that JUnit should be used to execute the tests. To configure JUnit specific options, see open fun useJUnit(testFrameworkConfigure: Closure<Any>): Unit
Specifies that JUnit should be used to execute the tests, configuring JUnit specific options. The supplied closure configures an instance of , which can be used to configure how JUnit runs. open fun useJUnit(testFrameworkConfigure: Action<in JUnitOptions>): Unit
Specifies that JUnit should be used to execute the tests, configuring JUnit specific options. The supplied action configures an instance of , which can be used to configure how JUnit runs. |
|
open fun useJUnitPlatform(): Unit
Specifies that JUnit Platform (a.k.a. JUnit 5) should be used to execute the tests. To configure JUnit platform specific options, see open fun useJUnitPlatform(testFrameworkConfigure: Action<in JUnitPlatformOptions>): Unit
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 , which can be used to configure how JUnit platform runs. |
|
open fun useTestNG(): Unit
Specifies that TestNG should be used to execute the tests. To configure TestNG specific options, see open fun useTestNG(testFrameworkConfigure: Closure<Any>): Unit
Specifies that TestNG should be used to execute the tests, configuring TestNG specific options. The supplied closure configures an instance of , which can be used to configure how TestNG runs. open fun useTestNG(testFrameworkConfigure: Action<in TestFrameworkOptions>): Unit
Specifies that TestNG should be used to execute the tests, configuring TestNG specific options. The supplied action configures an instance of , which can be used to configure how TestNG runs. |
|
open fun workingDir(dir: Any): Test
{@inheritDoc} |
open fun addTestListener(listener: TestListener): Unit
Registers a test listener with this task. Consider also the following handy methods for quicker hooking into test execution: This listener will NOT be notified of tests executed by other tasks. To get that behavior, use |
|
open fun addTestOutputListener(listener: TestOutputListener): Unit
Registers a output listener with this task. Quicker way of hooking into output events is using the |
|
open fun afterSuite(closure: Closure<Any>): Unit
Adds a closure to be notified after a test suite has executed. A TestDescriptor and TestResult instance are passed to the closure as a parameter. This method is also called after all test suites are executed. The provided descriptor will have a null parent suite. |
|
open fun afterTest(closure: Closure<Any>): Unit
Adds a closure to be notified after a test has executed. A TestDescriptor and TestResult instance are passed to the closure as a parameter. |
|
open fun beforeSuite(closure: Closure<Any>): Unit
Adds a closure to be notified before a test suite is executed. A TestDescriptor instance is passed to the closure as a parameter. This method is also called before any test suites are executed. The provided descriptor will have a null parent suite. |
|
open fun beforeTest(closure: Closure<Any>): Unit
Adds a closure to be notified before a test is executed. A TestDescriptor instance is passed to the closure as a parameter. |
|
open fun getBinResultsDir(): File
Returns the root folder for the test results in internal binary format. |
|
open fun getBinaryResultsDirectory(): DirectoryProperty
Returns the root directory property for the test results in internal binary format. |
|
open fun getFilter(): TestFilter
Allows filtering tests for execution. |
|
open fun getIgnoreFailures(): Boolean
{@inheritDoc} |
|
open fun getReports(): TestTaskReports
The reports that this task potentially produces. |
|
open fun getTestLogging(): TestLoggingContainer
Allows to set options related to which test events are logged to the console, and on which detail level. For example, to show more information about exceptions use: For further information see TestLoggingContainer.
|
|
open fun onOutput(closure: Closure<Any>): Unit
Adds a closure to be notified when output from the test received. A TestDescriptor and TestOutputEvent instance are passed to the closure as a parameter.
|
|
open fun removeTestListener(listener: TestListener): Unit
Unregisters a test listener with this task. This method will only remove listeners that were added by calling |
|
open fun removeTestOutputListener(listener: TestOutputListener): Unit
Unregisters a test output listener with this task. This method will only remove listeners that were added by calling |
|
open fun reports(closure: Closure<Any>): TestTaskReports open fun reports(configureAction: Action<in TestTaskReports>): TestTaskReports
Configures the reports that this task potentially produces. |
|
open fun setBinResultsDir(binResultsDir: File): Unit
Sets the root folder for the test results in internal binary format. |
|
open fun setIgnoreFailures(ignoreFailures: Boolean): Unit
{@inheritDoc} |
|
open fun testLogging(closure: Closure<Any>): Unit open fun testLogging(action: Action<in TestLoggingContainer>): Unit
Allows configuring the logging of the test execution, for example log eagerly the standard output, etc.
|