api / org.gradle.api.tasks.testing / AbstractTestTask

AbstractTestTask

abstract class AbstractTestTask : ConventionTask, VerificationTask, Reporting<TestTaskReports>

Abstract class for all test task.

Note: This abstract class is not intended for implementation by build script or plugin authors.

Since
4.4

Constructors

<init>

AbstractTestTask()

Functions

addTestListener

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: #beforeTest(groovy.lang.Closure), , #beforeSuite(groovy.lang.Closure), #afterSuite(groovy.lang.Closure)

This listener will NOT be notified of tests executed by other tasks. To get that behavior, use org.gradle.api.invocation.Gradle#addListener(Object).

addTestOutputListener

open fun addTestOutputListener(listener: TestOutputListener): Unit

Registers a output listener with this task. Quicker way of hooking into output events is using the #onOutput(groovy.lang.Closure) method.

afterSuite

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.

afterTest

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.

beforeSuite

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.

beforeTest

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.

executeTests

open fun executeTests(): Unit

getBinResultsDir

open fun getBinResultsDir(): File

Returns the root folder for the test results in internal binary format.

getBinaryResultsDirectory

open fun getBinaryResultsDirectory(): DirectoryProperty

Returns the root directory property for the test results in internal binary format.

getFilter

open fun getFilter(): TestFilter

Allows filtering tests for execution.

getIgnoreFailures

open fun getIgnoreFailures(): Boolean

{@inheritDoc}

getReports

open fun getReports(): TestTaskReports

The reports that this task potentially produces.

getTestLogging

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:

 apply plugin: 'java' test.testLogging { exceptionFormat "full" } 
For further information see TestLoggingContainer.

onOutput

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.

 apply plugin: 'java' test { onOutput { descriptor, event -> if (event.destination == TestOutputEvent.Destination.StdErr) { logger.error("Test: " + descriptor + ", error: " + event.message) } } } 

removeTestListener

open fun removeTestListener(listener: TestListener): Unit

Unregisters a test listener with this task. This method will only remove listeners that were added by calling #addTestListener(TestListener) on this task. If the listener was registered with Gradle using org.gradle.api.invocation.Gradle#addListener(Object) this method will not do anything. Instead, use .

removeTestOutputListener

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 #addTestOutputListener(TestOutputListener) on this task. If the listener was registered with Gradle using org.gradle.api.invocation.Gradle#addListener(Object) this method will not do anything. Instead, use .

reports

open fun reports(closure: Closure<Any>): TestTaskReports
open fun reports(configureAction: Action<in TestTaskReports>): TestTaskReports

Configures the reports that this task potentially produces.

setBinResultsDir

open fun setBinResultsDir(binResultsDir: File): Unit

Sets the root folder for the test results in internal binary format.

setIgnoreFailures

open fun setIgnoreFailures(ignoreFailures: Boolean): Unit

{@inheritDoc}

setTestNameIncludePatterns

open fun setTestNameIncludePatterns(testNamePattern: MutableList<String>): AbstractTestTask

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 see TestFilter

testLogging

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.

 apply plugin: 'java' // makes the standard streams (err and out) visible at console when running tests test.testLogging { showStandardStreams = true } 

Inheritors

Test

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 

XCTest

open class XCTest : AbstractTestTask

Executes XCTest tests. Test are always run in a single execution.