api / org.gradle.api.tasks.testing

Package org.gradle.api.tasks.testing



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

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.


interface JUnitXmlReport : DirectoryReport

The JUnit XML files, commonly used to communicate results to CI servers.


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 


interface TestDescriptor

Describes a test. A test may be a single atomic test, such as the execution of a test method, or it may be a composite test, made up of zero or more tests.


interface TestFilter

Allows filtering tests for execution. Some examples:

 apply plugin: 'java' test { filter { //specific test class, this can match 'SomeTest' class and corresponding method under any package includeTestsMatching "SomeTest" includeTestsMatching "SomeTest.someTestMethod*" //specific test class includeTestsMatching "org.gradle.SomeTest" //specific test class and method includeTestsMatching "org.gradle.SomeTest.someSpecificFeature" includeTest "org.gradle.SomeTest", "someTestMethod" //specific test method, use wildcard includeTestsMatching "*SomeTest.someSpecificFeature" //specific test class, wildcard for packages includeTestsMatching "*.SomeTest" //all classes in package, recursively includeTestsMatching "com.gradle.tooling.*" //all integration tests, by naming convention includeTestsMatching "*IntegTest" //only ui tests from integration tests, by some naming convention includeTestsMatching "*IntegTest*ui" } } 


open class TestFrameworkOptions

The base class for any test framework specific options.


interface TestListener

Interface for listening to test execution. The intent is to be framework agnostic. Currently this interface can support feedback from JUnit and TestNG tests.


interface TestOutputEvent

Standard output or standard error message logged during the execution of the test


interface TestOutputListener

Listens to the output events like printing to standard output or error


open class TestReport : DefaultTask

Generates an HTML test report from the results of one or more Test tasks.


interface TestResult

Describes a test result.


interface TestTaskReports : ReportContainer<Report>

The reports produced by the Test task.



open class TestExecutionException : GradleException

A TestExecutionException is thrown when no tests can be found that match the specified test filters.