Package org.gradle.api.tasks.testing

# Class AbstractTestTask

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
org.gradle.api.internal.ConventionTask
org.gradle.api.tasks.testing.AbstractTestTask

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`, `VerificationTask`, `Configurable<Task>`

Direct Known Subclasses:
  `Test`, `XCTest`

@DisableCachingByDefault(because="Abstract super-class, not to be instantiated directly") public abstract class AbstractTestTask extends org.gradle.api.internal.ConventionTask implements VerificationTask, Reporting<TestTaskReports>
Abstract class for all test tasks.

- 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.

Since:
  4.4

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface org.gradle.api.Named

  `Named.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
  `AbstractTestTask()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addTestListener(TestListener listener)`
  Registers a test listener with this task.
  `void`
  `addTestMetadataListener(TestMetadataListener listener)`
  Registers a metadata listener with this task.
  `void`
  `addTestOutputListener(TestOutputListener listener)`
  Registers a output listener with this task.
  `void`
  `afterSuite(Closure closure)`
  Deprecated.
  Replace with `addTestListener(TestListener)` and a `TestListener`.
  `void`
  `afterTest(Closure closure)`
  Deprecated.
  Replace with `addTestListener(TestListener)` and a `TestListener`.
  `void`
  `beforeSuite(Closure closure)`
  Deprecated.
  Replace with `addTestListener(TestListener)` and a `TestListener`.
  `void`
  `beforeTest(Closure closure)`
  Deprecated.
  Replace with `addTestListener(TestListener)` and a `TestListener`.
  `protected abstract org.gradle.api.internal.tasks.testing.TestExecuter<? extends org.gradle.api.internal.tasks.testing.TestExecutionSpec>`
  `createTestExecuter()`
  Creates test executer.
  `protected abstract org.gradle.api.internal.tasks.testing.TestExecutionSpec`
  `createTestExecutionSpec()`
  Creates test execution specification.
  `void`
  `executeTests()`
  `abstract DirectoryProperty`
  `getBinaryResultsDirectory()`
  Returns the root directory property for the test results in internal binary format.
  `protected abstract org.gradle.internal.operations.BuildOperationExecutor`
  `getBuildOperationExecutor()`
  `protected abstract org.gradle.internal.operations.BuildOperationRunner`
  `getBuildOperationRunner()`
  `(package private) boolean`
  `getFailFast()`
  `abstract Property<Boolean>`
  `getFailOnNoDiscoveredTests()`
  Whether the task should fail if test sources are present, but no tests are discovered during test execution.
  `protected abstract FileSystemOperations`
  `getFileSystemOperations()`
  `TestFilter`
  `getFilter()`
  Allows filtering tests for execution.
  `protected abstract org.gradle.internal.nativeintegration.network.HostnameLookup`
  `getHostnameLookup()`
  `boolean`
  `getIgnoreFailures()`
  Specifies whether the build should break when the verifications performed by this task fail.
  `protected abstract org.gradle.internal.reflect.Instantiator`
  `getInstantiator()`
  `protected abstract org.gradle.internal.event.ListenerManager`
  `getListenerManager()`
  `protected List<String>`
  `getNoMatchingTestErrorReasons()`
  Returns the reasons for no matching test error.
  `protected abstract ObjectFactory`
  `getObjectFactory()`
  `protected abstract org.gradle.internal.logging.progress.ProgressLoggerFactory`
  `getProgressLoggerFactory()`
  `protected int`
  `getReportEntrySkipLevels()`
  Returns the number of top level entries to skip in reports.
  `TestTaskReports`
  `getReports()`
  The reports that this task potentially produces.
  `protected abstract TestEventReporterFactory`
  `getTestEventReporterFactory()`
  `TestLoggingContainer`
  `getTestLogging()`
  Allows to set options related to which test events are logged to the console, and on which detail level.
  `protected abstract org.gradle.internal.logging.text.StyledTextOutputFactory`
  `getTextOutputFactory()`
  `void`
  `onOutput(Closure closure)`
  Deprecated.
  Replace with `addTestOutputListener(TestOutputListener)` and a `TestOutputListener`.
  `void`
  `removeTestListener(TestListener listener)`
  Unregisters a test listener with this task.
  `void`
  `removeTestMetadataListener(TestMetadataListener listener)`
  Unregisters a test metadata listener with this task.
  `void`
  `removeTestOutputListener(TestOutputListener listener)`
  Unregisters a test output listener with this task.
  `TestTaskReports`
  `reports(Closure closure)`
  Configures the reports that this task potentially produces.
  `TestTaskReports`
  `reports(Action<? super TestTaskReports> configureAction)`
  Configures the reports that this task potentially produces.
  `(package private) void`
  `setFailFast(boolean failFast)`
  `void`
  `setIgnoreFailures(boolean ignoreFailures)`
  Specifies whether the build should break when the verifications performed by this task fail.
  `AbstractTestTask`
  `setTestNameIncludePatterns(List<String> testNamePattern)`
  Sets the test name patterns to be included in execution.
  `(package private) void`
  `setTestReporter(org.gradle.api.internal.tasks.testing.report.TestReporter testReporter)`
  Deprecated.
  Only present for compatibility with cashapp/paparazzi.
  `void`
  `testLogging(Closure closure)`
  Allows configuring the logging of the test execution, for example log eagerly the standard output, etc.
  `void`
  `testLogging(Action<? super TestLoggingContainer> action)`
  Allows configuring the logging of the test execution, for example log eagerly the standard output, etc.
  `(package private) boolean`
  `testsAreNotFiltered()`

  ### 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, doNotTrackStateIf, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonsNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, restoreOnlyIf, restoreTaskActions, 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, notCompatibleWithConfigurationCache`

- ## Constructor Details

  - ### AbstractTestTask

    public AbstractTestTask()

- ## Method Details

  - ### getProgressLoggerFactory

    @Inject protected abstract org.gradle.internal.logging.progress.ProgressLoggerFactory getProgressLoggerFactory()

  - ### getTextOutputFactory

    @Inject protected abstract org.gradle.internal.logging.text.StyledTextOutputFactory getTextOutputFactory()

  - ### getHostnameLookup

    @Inject protected abstract org.gradle.internal.nativeintegration.network.HostnameLookup getHostnameLookup()

  - ### getBuildOperationRunner

    @Inject protected abstract org.gradle.internal.operations.BuildOperationRunner getBuildOperationRunner()

  - ### getBuildOperationExecutor

    @Inject protected abstract org.gradle.internal.operations.BuildOperationExecutor getBuildOperationExecutor()

  - ### getObjectFactory

    @Inject protected abstract ObjectFactory getObjectFactory()

  - ### getInstantiator

    @Inject protected abstract org.gradle.internal.reflect.Instantiator getInstantiator()

  - ### getListenerManager

    @Inject protected abstract org.gradle.internal.event.ListenerManager getListenerManager()

  - ### getFileSystemOperations

    @Inject protected abstract FileSystemOperations getFileSystemOperations()

  - ### getTestEventReporterFactory

    @Inject protected abstract TestEventReporterFactory getTestEventReporterFactory()

  - ### createTestExecuter

    protected abstract org.gradle.api.internal.tasks.testing.TestExecuter<? extends org.gradle.api.internal.tasks.testing.TestExecutionSpec> createTestExecuter()
    Creates test executer. For internal use only.
    Since:
      4.4

  - ### createTestExecutionSpec

    protected abstract org.gradle.api.internal.tasks.testing.TestExecutionSpec createTestExecutionSpec()
    Creates test execution specification. For internal use only.
    Since:
      4.4

  - ### getReportEntrySkipLevels

    @Internal protected int getReportEntrySkipLevels()
    Returns the number of top level entries to skip in reports. For internal use only.
    Since:
      9.3.0

  - ### setTestReporter

    @Deprecated void setTestReporter(org.gradle.api.internal.tasks.testing.report.TestReporter testReporter)
    Deprecated.
    Only present for compatibility with cashapp/paparazzi. No replacement.
    Sets the test reporter to use for generating reports.

  - ### getBinaryResultsDirectory

    @OutputDirectory public abstract DirectoryProperty getBinaryResultsDirectory()
    Returns the root directory property for the test results in internal binary format.
    Since:
      4.4

  - ### addTestListener

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

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

    Parameters:
      `listener` - The listener to add.

  - ### addTestOutputListener

    public void addTestOutputListener(TestOutputListener listener)
    Registers a output listener with this task. Quicker way of hooking into output events is using the `onOutput(Closure)` method.
    Parameters:
      `listener` - The listener to add.

  - ### addTestMetadataListener

    @Incubating public void addTestMetadataListener(TestMetadataListener listener)
    Registers a metadata listener with this task.
    Parameters:
      `listener` - The listener to add.
    Since:
      9.4.0

  - ### removeTestListener

    public void removeTestListener(TestListener listener)
    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 `Gradle.addListener(Object)` this method will not do anything. Instead, use `Gradle.removeListener(Object)`.
    Parameters:
      `listener` - The listener to remove.

  - ### removeTestOutputListener

    public void removeTestOutputListener(TestOutputListener listener)
    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 `Gradle.addListener(Object)` this method will not do anything. Instead, use `Gradle.removeListener(Object)`.
    Parameters:
      `listener` - The listener to remove.

  - ### removeTestMetadataListener

    @Incubating public void removeTestMetadataListener(TestMetadataListener listener)
    Unregisters a test metadata listener with this task. This method will only remove listeners that were added by calling `addTestMetadataListener(TestMetadataListener)` on this task. If the listener was registered with Gradle using `Gradle.addListener(Object)` this method will not do anything. Instead, use `Gradle.removeListener(Object)`.
    Parameters:
      `listener` - The listener to remove.
    Since:
      9.4.0

  - ### getIgnoreFailures

    @Internal public boolean getIgnoreFailures()
    Specifies whether the build should break when the verifications performed by this task fail.
    Specified by:
      `getIgnoreFailures` in interface `VerificationTask`
    Returns:
      false, when the build should break on failure, true when the failures should be ignored.

  - ### setIgnoreFailures

    public void setIgnoreFailures(boolean ignoreFailures)
    Specifies whether the build should break when the verifications performed by this task fail.
    Specified by:
      `setIgnoreFailures` in interface `VerificationTask`
    Parameters:
      `ignoreFailures` - false to break the build on failure, true to ignore the failures. The default is false.

  - ### onOutput

    @Deprecated public void onOutput(Closure closure)
    Deprecated.
    Replace with `addTestOutputListener(TestOutputListener)` and a `TestOutputListener`.
    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)
                }
            }
         }

    Parameters:
      `closure` - The closure to call.

  - ### beforeSuite

    @Deprecated public void beforeSuite(Closure closure)
    Deprecated.
    Replace with `addTestListener(TestListener)` and a `TestListener`.

    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.

    Parameters:
      `closure` - The closure to call.

  - ### afterSuite

    @Deprecated public void afterSuite(Closure closure)
    Deprecated.
    Replace with `addTestListener(TestListener)` and a `TestListener`.

    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.

    Parameters:
      `closure` - The closure to call.

  - ### beforeTest

    @Deprecated public void beforeTest(Closure closure)
    Deprecated.
    Replace with `addTestListener(TestListener)` and a `TestListener`.
    Adds a closure to be notified before a test is executed. A `TestDescriptor` instance is passed to the closure as a parameter.
    Parameters:
      `closure` - The closure to call.

  - ### afterTest

    @Deprecated public void afterTest(Closure closure)
    Deprecated.
    Replace with `addTestListener(TestListener)` and a `TestListener`.
    Adds a closure to be notified after a test has executed. A `TestDescriptor` and `TestResult` instance are passed to the closure as a parameter.
    Parameters:
      `closure` - The closure to call.

  - ### getTestLogging

    public TestLoggingContainer getTestLogging()
    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`.
    Returns:
      this

  - ### testLogging

    public void testLogging(@DelegatesTo(TestLoggingContainer.class) Closure closure)
    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
         }

    Parameters:
      `closure` - configure closure

  - ### testLogging

    public void testLogging(Action<? super TestLoggingContainer> action)
    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
         }

    Parameters:
      `action` - configure action
    Since:
      3.5

  - ### executeTests

    public void executeTests()

  - ### testsAreNotFiltered

    boolean testsAreNotFiltered()

  - ### getNoMatchingTestErrorReasons

    @Internal protected List<String> getNoMatchingTestErrorReasons()
    Returns the reasons for no matching test error.
    Since:
      4.5

  - ### setTestNameIncludePatterns

    public AbstractTestTask setTestNameIncludePatterns(List<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 see `TestFilter`

  - ### getFailFast

    @Internal boolean getFailFast()

  - ### setFailFast

    void setFailFast(boolean failFast)

  - ### getReports

    public TestTaskReports getReports()
    The reports that this task potentially produces.
    Specified by:
      `getReports` in interface `Reporting<TestTaskReports>`
    Returns:
      The reports that this task potentially produces

  - ### reports

    public TestTaskReports reports(Closure closure)
    Configures the reports that this task potentially produces.
    Specified by:
      `reports` in interface `Reporting<TestTaskReports>`
    Parameters:
      `closure` - The configuration
    Returns:
      The reports that this task potentially produces

  - ### reports

    public TestTaskReports reports(Action<? super TestTaskReports> configureAction)
    Configures the reports that this task potentially produces.
    Specified by:
      `reports` in interface `Reporting<TestTaskReports>`
    Parameters:
      `configureAction` - The configuration
    Returns:
      The reports that this task potentially produces

  - ### getFilter

    public TestFilter getFilter()
    Allows filtering tests for execution.
    Returns:
      filter object
    Since:
      1.10

  - ### getFailOnNoDiscoveredTests

    @Input public abstract Property<Boolean> getFailOnNoDiscoveredTests()
    Whether the task should fail if test sources are present, but no tests are discovered during test execution. Defaults to true.
    Since:
      9.0.0