Movatterモバイル変換


[0]ホーム

URL:


Test

Table of Contents

Properties
Methods
Script blocks
Property details
Method details
Script block details
API Documentation: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.

apply plugin:'java'// adds 'test' tasktest {// 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 (seeTest.getDebug()) in an ad-hoc manner by supplying the `--debug-jvm` switch when invoking the build.

gradle someTestTask --debug-jvm

Properties

PropertyDescription
allJvmArgs

The full set of arguments to use to launch the JVM for the process. This includes arguments to definesystem properties, the minimum/maximum heap size, and the bootstrap classpath.

binResultsDir
Deprecated
Replaced

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

bootstrapClasspath

The bootstrap classpath to use for the process. The default bootstrap classpath for the JVM is used whenthis classpath is empty.

classpath

The classpath to use to execute the tests.

debug

Determines whether debugging is enabled for the test process. When enabled — debug = true — the processis started in a suspended state, listening on port 5005. You should disable parallel test execution whendebugging and you will need to reattach the debugger occasionally if you use a non-zero value forTest.getForkEvery().

enableAssertions

Returns true if assertions are enabled for the process.

environment

The environment variables to use for the process. Defaults to the environment of this process.

excludes

The exclude patterns for test execution.

executable

The name of the executable to use.

failFast

Indicates if this task will fail on the first failed test

forkEvery

The maximum number of test classes to execute in a forked test process. The forked test process will be restarted when this limit is reached.

ignoreFailures

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

includes

The include patterns for test execution.

jvmArgs

The extra arguments to use to launch the JVM for the process. Does not include system properties and theminimum/maximum heap size.

jvmArgumentProviders

Command line argument providers for the java process to fork.

maxHeapSize

The maximum heap size for the process, if any.

maxParallelForks

The maximum number of test processes to start in parallel.

minHeapSize

The minimum heap size for the process, if any.

options

Returns test framework specific options. Make sure to callTest.useJUnit(),Test.useJUnitPlatform() orTest.useTestNG() before using this method.

reports

The reports that this task potentially produces.

scanForTestClasses

Specifies whether test classes should be detected. Whentrue the classes which match the include and exclude patterns are scanned for test classes, and any found are executed. Whenfalse the classes which match the include and exclude patterns are executed.

systemProperties

The system properties which will be used for the process.

testClassesDirs

The directories for the compiled test sources.

testLogging

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:

workingDir

The working directory for the process. Defaults to the project directory.

Properties added by thejacoco plugin

PropertyDescription
jacoco

TheJacocoTaskExtension added by the jacoco plugin.

Methods

MethodDescription
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 theAbstractTestTask.onOutput(groovy.lang.Closure) method.

afterSuite(closure)

Adds a closure to be notified after a test suite has executed. ATestDescriptor andTestResult instance are passed to the closure as aparameter.

afterTest(closure)

Adds a closure to be notified after a test has executed. ATestDescriptor andTestResult instance are passed to the closure as a parameter.

beforeSuite(closure)

Adds a closure to be notified before a test suite is executed. ATestDescriptor instance is passed to the closure as a parameter.

beforeTest(closure)

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

bootstrapClasspath(classpath)

Adds the given values to the end of the bootstrap classpath for the process.

copyTo(target)

Copies these options to the given options.

copyTo(target)

Copies these options to the given target options.

environment(name, value)

Adds an environment variable to the environment for this process.

environment(environmentVariables)

Adds some environment variables to the environment for this process.

exclude(excludeSpec)

Adds an exclude spec. This method may be called multiple times to append new specs.The given closure is passed aFileTreeElement as its parameter. The closure should return true or false. Example:

exclude(excludes)

Adds exclude patterns for the files in the test classes directory (e.g. '**/*Test.class')).

exclude(excludes)

Adds exclude patterns for the files in the test classes directory (e.g. '**/*Test.class')).

exclude(excludeSpec)

Adds an exclude spec. This method may be called multiple times to append new specs.If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not matchany exclude pattern to be processed.

executable(executable)

Sets the name of the executable to use.

include(includeSpec)

Adds an include spec. This method may be called multiple times to append new specs. The given closure is passed aFileTreeElement as its parameter.If includes are not provided, then all files in this container will be included. If includes are provided, then afile must match at least one of the include patterns or specs to be included.

include(includes)

Adds include patterns for the files in the test classes directory (e.g. '**/*Test.class')).

include(includes)

Adds include patterns for the files in the test classes directory (e.g. '**/*Test.class')).

include(includeSpec)

Adds an include spec. This method may be called multiple times to append new specs.If includes are not provided, then all files in this container will be included. If includes are provided, then afile must match at least one of the include patterns or specs to be included.

jvmArgs(arguments)

Adds some arguments to use to launch the JVM for the process.

jvmArgs(arguments)

Adds some arguments to use to launch the JVM for the process.

onOutput(closure)

Adds a closure to be notified when output from the test received. ATestDescriptor andTestOutputEvent instance arepassed to the closure as a parameter.

options(testFrameworkConfigure)

Configures test framework specific options. Make sure to callTest.useJUnit(),Test.useJUnitPlatform() orTest.useTestNG() before using this method.

removeTestListener(listener)

Unregisters a test listener with this task. This method will only remove listeners that were added by callingAbstractTestTask.addTestListener(org.gradle.api.tasks.testing.TestListener) on this task. If the listener wasregistered with Gradle usingGradle.addListener(java.lang.Object) this method will not do anything. Instead, useGradle.removeListener(java.lang.Object).

removeTestOutputListener(listener)

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

reports(configureAction)

Configures the reports that this task potentially produces.

setTestNameIncludePatterns(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 seeTestFilter

systemProperties(properties)

Adds some system properties to use for the process.

useJUnit()

Specifies that JUnit should be used to execute the tests.

useJUnit(testFrameworkConfigure)

Specifies that JUnit should be used to execute the tests, configuring JUnit specific options.

useJUnit(testFrameworkConfigure)

Specifies that JUnit should be used to execute the tests, configuring JUnit specific options.

useTestNG()

Specifies that TestNG should be used to execute the tests.

useTestNG(testFrameworkConfigure)

Specifies that TestNG should be used to execute the tests, configuring TestNG specific options.

useTestNG(testFrameworkConfigure)

Specifies that TestNG should be used to execute the tests, configuring TestNG specific options.

workingDir(dir)

Sets the working directory for the process. The supplied argument is evaluated as perProject.file(java.lang.Object).

Script blocks

BlockDescription
options

Configures test framework specific options. Make sure to callTest.useJUnit(),Test.useJUnitPlatform() orTest.useTestNG() before using this method.

Script blocks added by thejacoco plugin

BlockDescription
jacoco

Configures theJacocoTaskExtension added by the jacoco plugin.

Property details

List<String>allJvmArgs

The full set of arguments to use to launch the JVM for the process. This includes arguments to definesystem properties, the minimum/maximum heap size, and the bootstrap classpath.

FilebinResultsDir

Note: This property isdeprecated and will be removed in the next major version of Gradle.

Note: This property has been replaced by binaryResultsDirectory.

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

Default:
project.testResultsDir/binary/task.name

FileCollectionbootstrapClasspath

The bootstrap classpath to use for the process. The default bootstrap classpath for the JVM is used whenthis classpath is empty.

Default withjava plugin:
[]

The classpath to use to execute the tests.

Default withjava plugin:
project.sourceSets.test.runtimeClasspath

booleandebug

Determines whether debugging is enabled for the test process. When enabled — debug = true — the processis started in a suspended state, listening on port 5005. You should disable parallel test execution whendebugging and you will need to reattach the debugger occasionally if you use a non-zero value forTest.getForkEvery().

Since Gradle 5.6, you can configure the port and other Java debug properties viaJavaForkOptions.debugOptions(org.gradle.api.Action).

Default withjava plugin:
false

booleanenableAssertions

Returns true if assertions are enabled for the process.

Default withjava plugin:
true

Map<String,Object>environment

The environment variables to use for the process. Defaults to the environment of this process.

Default withjava plugin:
environment of the current process

Set<String>excludes

The exclude patterns for test execution.

Default withjava plugin:
[]

Stringexecutable

The name of the executable to use.

Default withjava plugin:
java command for the current JVM.

booleanfailFast

Indicates if this task will fail on the first failed test

Default withjava plugin:
false

longforkEvery

The maximum number of test classes to execute in a forked test process. The forked test process will be restarted when this limit is reached.

By default, Gradle automatically uses a separate JVM when executing tests.

  • A value of0 (no limit) means to reuse the test process for all test classes. This is the default.
  • A value of1 means that a new test process is started forevery test class.This is very expensive.
  • A value ofN means that a new test process is started afterN test classes.

This property can have a large impact on performance due to the cost of stopping and starting each test process. It is unusual for this property to be changed from the default.

Default withjava plugin:
0

booleanignoreFailures

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

Set<String>includes

The include patterns for test execution.

Default withjava plugin:
[]

List<String>jvmArgs

The extra arguments to use to launch the JVM for the process. Does not include system properties and theminimum/maximum heap size.

Default withjava plugin:
[]

List<CommandLineArgumentProvider>jvmArgumentProviders (read-only)

Command line argument providers for the java process to fork.

Default withjava plugin:
[]

StringmaxHeapSize

The maximum heap size for the process, if any.

Default withjava plugin:
null

intmaxParallelForks

The maximum number of test processes to start in parallel.

By default, Gradle executes a single test class at a time.

  • A value of1 means to only execute a single test class in a single test process at a time. This is the default.
  • A value ofN means that up toN test processes will be started to execute test classes.This can improve test execution time by running multiple test classes in parallel.

This property cannot exceed the value of max-workers for the current build. Gradle will also limit the number of started test processes across allTest tasks.

Default withjava plugin:
1

StringminHeapSize

The minimum heap size for the process, if any.

Default withjava plugin:
null

TestFrameworkOptionsoptions (read-only)

Returns test framework specific options. Make sure to callTest.useJUnit(),Test.useJUnitPlatform() orTest.useTestNG() before using this method.

TestTaskReportsreports (read-only)

The reports that this task potentially produces.

booleanscanForTestClasses

Specifies whether test classes should be detected. Whentrue the classes which match the include and exclude patterns are scanned for test classes, and any found are executed. Whenfalse the classes which match the include and exclude patterns are executed.

Default withjava plugin:
true

Map<String,Object>systemProperties

The system properties which will be used for the process.

Default withjava plugin:
[:]

FileCollectiontestClassesDirs

The directories for the compiled test sources.

Default withjava plugin:
project.sourceSets.test.output.classesDirs

TestLoggingContainertestLogging (read-only)

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

FileworkingDir

The working directory for the process. Defaults to the project directory.

Default withjava plugin:
project.projectDir

JacocoTaskExtensionjacoco (read-only)

TheJacocoTaskExtension added by the jacoco plugin.

Method details

voidaddTestListener(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. Toget that behavior, useGradle.addListener(java.lang.Object).

voidaddTestOutputListener(TestOutputListener listener)

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

voidafterSuite(Closure closure)

Adds a closure to be notified after a test suite has executed. ATestDescriptor andTestResult instance are passed to the closure as aparameter.

This method is also called after all test suites are executed. The provided descriptor will have a null parent suite.

voidafterTest(Closure closure)

Adds a closure to be notified after a test has executed. ATestDescriptor andTestResult instance are passed to the closure as a parameter.

voidbeforeSuite(Closure closure)

Adds a closure to be notified before a test suite is executed. ATestDescriptor 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.

voidbeforeTest(Closure closure)

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

TestbootstrapClasspath(Object... classpath)

Adds the given values to the end of the bootstrap classpath for the process.

TestcopyTo(JavaForkOptions target)

Copies these options to the given options.

TestcopyTo(ProcessForkOptions target)

Copies these options to the given target options.

Testenvironment(String name,Object value)

Adds an environment variable to the environment for this process.

Testenvironment(Map<String, ?> environmentVariables)

Adds some environment variables to the environment for this process.

Testexclude(Closure excludeSpec)

Adds an exclude spec. This method may be called multiple times to append new specs.The given closure is passed aFileTreeElement as its parameter. The closure should return true or false. Example:

copySpec {  from'source'  into'destination'//an example of excluding files from certain configuration:  exclude { it.file in configurations.someConf.files }}

If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not matchany exclude pattern to be processed.

Testexclude(Iterable<String> excludes)

Adds exclude patterns for the files in the test classes directory (e.g. '**/*Test.class')).

Testexclude(String... excludes)

Adds exclude patterns for the files in the test classes directory (e.g. '**/*Test.class')).

Testexclude(Spec<FileTreeElement> excludeSpec)

Adds an exclude spec. This method may be called multiple times to append new specs.If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not matchany exclude pattern to be processed.

Testexecutable(Object executable)

Sets the name of the executable to use.

Testinclude(Closure includeSpec)

Adds an include spec. This method may be called multiple times to append new specs. The given closure is passed aFileTreeElement as its parameter.If includes are not provided, then all files in this container will be included. If includes are provided, then afile must match at least one of the include patterns or specs to be included.

Testinclude(Iterable<String> includes)

Adds include patterns for the files in the test classes directory (e.g. '**/*Test.class')).

Testinclude(String... includes)

Adds include patterns for the files in the test classes directory (e.g. '**/*Test.class')).

Testinclude(Spec<FileTreeElement> includeSpec)

Adds an include spec. This method may be called multiple times to append new specs.If includes are not provided, then all files in this container will be included. If includes are provided, then afile must match at least one of the include patterns or specs to be included.

TestjvmArgs(Iterable<?> arguments)

Adds some arguments to use to launch the JVM for the process.

TestjvmArgs(Object... arguments)

Adds some arguments to use to launch the JVM for the process.

voidonOutput(Closure closure)

Adds a closure to be notified when output from the test received. ATestDescriptor andTestOutputEvent instance arepassed 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)       }   }}

TestFrameworkOptionsoptions(Action<? superTestFrameworkOptions> testFrameworkConfigure)

Configures test framework specific options. Make sure to callTest.useJUnit(),Test.useJUnitPlatform() orTest.useTestNG() before using this method.

voidremoveTestListener(TestListener listener)

Unregisters a test listener with this task. This method will only remove listeners that were added by callingAbstractTestTask.addTestListener(org.gradle.api.tasks.testing.TestListener) on this task. If the listener wasregistered with Gradle usingGradle.addListener(java.lang.Object) this method will not do anything. Instead, useGradle.removeListener(java.lang.Object).

voidremoveTestOutputListener(TestOutputListener listener)

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

TestTaskReportsreports(Action<? superTestTaskReports> configureAction)

Configures the reports that this task potentially produces.

AbstractTestTasksetTestNameIncludePatterns(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 seeTestFilter

TestsystemProperties(Map<String, ?> properties)

Adds some system properties to use for the process.

voiduseJUnit()

Specifies that JUnit should be used to execute the tests.

To configure JUnit specific options, seeTest.useJUnit(groovy.lang.Closure).

voiduseJUnit(Closure testFrameworkConfigure)

Specifies that JUnit should be used to execute the tests, configuring JUnit specific options.

The supplied closure configures an instance ofJUnitOptions, which can be used to configure how JUnit runs.

voiduseJUnit(Action<? superJUnitOptions> testFrameworkConfigure)

Specifies that JUnit should be used to execute the tests, configuring JUnit specific options.

The supplied action configures an instance ofJUnitOptions, which can be used to configure how JUnit runs.

voiduseTestNG()

Specifies that TestNG should be used to execute the tests.

To configure TestNG specific options, seeTest.useTestNG(groovy.lang.Closure).

voiduseTestNG(Closure testFrameworkConfigure)

Specifies that TestNG should be used to execute the tests, configuring TestNG specific options.

The supplied closure configures an instance ofTestNGOptions, which can be used to configure how TestNG runs.

voiduseTestNG(Action<? superTestNGOptions> testFrameworkConfigure)

Specifies that TestNG should be used to execute the tests, configuring TestNG specific options.

The supplied action configures an instance ofTestNGOptions, which can be used to configure how TestNG runs.

TestworkingDir(Object dir)

Sets the working directory for the process. The supplied argument is evaluated as perProject.file(java.lang.Object).

Script block details

options { }

Configures test framework specific options. Make sure to callTest.useJUnit(),Test.useJUnitPlatform() orTest.useTestNG() before using this method.

Delegates to:
TestFrameworkOptions fromoptions

jacoco { }

Configures theJacocoTaskExtension added by the jacoco plugin.

Delegates to:
JacocoTaskExtension fromjacoco

[8]ページ先頭

©2009-2025 Movatter.jp