AbstractTestTask - Gradle DSL Version 4.5.1

# AbstractTestTask

API Documentation: | `AbstractTestTask`

Known Subtypes: |
`Test`

Abstract class for all test task.

- Support for test listeners
- Support for reporting
- Support for report linking in the console output

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

### Properties

Property | Description
`binResultsDir` | Incubating The root folder for the test results in internal binary format.
`ignoreFailures` | Specifies whether the build should break when the verifications performed by this task fail.
`reports` | The reports that this task potentially produces.

### Methods

Method | Description
`addTestListener(listener)` | Registers a test listener with this task. Consider also the following handy methods for quicker hooking into test execution: `AbstractTestTask.beforeTest(groovy.lang.Closure)`, `AbstractTestTask.afterTest(groovy.lang.Closure)`, `AbstractTestTask.beforeSuite(groovy.lang.Closure)`, `AbstractTestTask.afterSuite(groovy.lang.Closure)`
`addTestOutputListener(listener)` | Registers a output listener with this task. Quicker way of hooking into output events is using the `AbstractTestTask.onOutput(groovy.lang.Closure)` method.
`afterSuite(closure)` | 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.
`afterTest(closure)` | 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(closure)` | Adds a closure to be notified before a test suite is executed. A `TestDescriptor` instance is passed to the closure as a parameter.
`beforeTest(closure)` | Adds a closure to be notified before a test is executed. A `TestDescriptor` instance is passed to the closure as a parameter.
`onOutput(closure)` | 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.
`removeTestListener(listener)` | Unregisters a test listener with this task. This method will only remove listeners that were added by calling `AbstractTestTask.addTestListener(org.gradle.api.tasks.testing.TestListener)` on this task. If the listener was registered with Gradle using `Gradle.addListener(java.lang.Object)` this method will not do anything. Instead, use `Gradle.removeListener(java.lang.Object)`.
`removeTestOutputListener(listener)` | Unregisters a test output listener with this task. This method will only remove listeners that were added by calling `AbstractTestTask.addTestOutputListener(org.gradle.api.tasks.testing.TestOutputListener)` on this task. If the listener was registered with Gradle using `Gradle.addListener(java.lang.Object)` this method will not do anything. Instead, use `Gradle.removeListener(java.lang.Object)`.
`reports(configureAction)` | Configures the reports that this task potentially produces.
`setTestNameIncludePatterns(testNamePattern)` | Incubating 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`

### Script blocks

Block | Description
`reports` | Configures the reports that this task potentially produces.

### Property details

#### `File` `binResultsDir`

Note: This property is incubating and may change in a future version of Gradle.

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

Default:
  ``project.testResultsDir`/binary/`task.name``

#### `boolean` `ignoreFailures`

Specifies whether the build should break when the verifications performed by this task fail.

#### `TestTaskReports` `reports` (read-only)

The reports that this task potentially produces.

### Method details

#### `void` `addTestListener`(`TestListener` listener)

Registers a test listener with this task. Consider also the following handy methods for quicker hooking into test execution: `AbstractTestTask.beforeTest(groovy.lang.Closure)`, `AbstractTestTask.afterTest(groovy.lang.Closure)`, `AbstractTestTask.beforeSuite(groovy.lang.Closure)`, `AbstractTestTask.afterSuite(groovy.lang.Closure)`

This listener will NOT be notified of tests executed by other tasks. To get that behavior, use `Gradle.addListener(java.lang.Object)`.

#### `void` `addTestOutputListener`(`TestOutputListener` listener)

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

#### `void` `afterSuite`(`Closure` closure)

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.

#### `void` `afterTest`(`Closure` closure)

Adds a closure to be notified after a test has executed. A `TestDescriptor` and `TestResult` instance are passed to the closure as a parameter.

#### `void` `beforeSuite`(`Closure` closure)

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.

#### `void` `beforeTest`(`Closure` closure)

Adds a closure to be notified before a test is executed. A `TestDescriptor` instance is passed to the closure as a parameter.

#### `void` `onOutput`(`Closure` closure)

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)
           }
       }
    }

#### `void` `removeTestListener`(`TestListener` listener)

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

#### `void` `removeTestOutputListener`(`TestOutputListener` listener)

Unregisters a test output listener with this task. This method will only remove listeners that were added by calling `AbstractTestTask.addTestOutputListener(org.gradle.api.tasks.testing.TestOutputListener)` on this task. If the listener was registered with Gradle using `Gradle.addListener(java.lang.Object)` this method will not do anything. Instead, use `Gradle.removeListener(java.lang.Object)`.

#### `TestTaskReports` `reports`(``Action`<? super `TestTaskReports`>` configureAction)

Configures the reports that this task potentially produces.

#### `AbstractTestTask` `setTestNameIncludePatterns`(``List`<`String`>` testNamePattern)

Note: This method is incubating and may change in a future version of Gradle.

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`

### Script block details

#### `reports` { }

Configures the reports that this task potentially produces.

Delegates to:
  `TestTaskReports` from `reports`