Test
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.
plugins {
id("java-library") // adds 'test' task
}
test {
// discover and execute JUnit4-based tests
useJUnit()
// discover and execute TestNG-based tests
useTestNG()
// discover and execute JUnit Platform-based tests
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
// skip an actual test execution
dryRun = 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
Properties
The extra properties extension in this object's extension container.
Functions
Kotlin extension function for org.gradle.api.tasks.testing.Test.environment.
Kotlin extension function for org.gradle.process.ProcessForkOptions.environment.
JavaLauncher
is not present.Kotlin extension function for org.gradle.process.ProcessForkOptions.setEnvironment.
Kotlin extension function for org.gradle.api.tasks.testing.Test.systemProperties.
Kotlin extension function for org.gradle.process.JavaForkOptions.systemProperties.
Returns the extension of the specified type.
Returns the extension of the specified extensionType.