api / org.gradle.testkit.runner / GradleRunner / <init>

<init>

GradleRunner()

Executes a Gradle build, allowing inspection of the outcome.

A Gradle runner can be used to functionally test build logic, by executing a contrived build. Assertions can then be made on the outcome of the build, such as the state of files created by the build, or what tasks were actually executed during the build.

A runner can be created via the #create() method.

Typically, the test code using the runner will programmatically create a build (e.g. by writing Gradle build files to a temporary space) to execute. The build to execute is effectively specified by the #withProjectDir(File)} method. It is a requirement that a project directory be set.

The #withArguments(String...) method allows the build arguments to be specified, just as they would be on the command line.

The #build() method can be used to invoke the build when it is expected to succeed, while the #buildAndFail() method can be used when the build is expected to fail.

GradleRunner instances are not thread safe and cannot be used concurrently. However, multiple instances are able to be used concurrently.

Please see the Gradle TestKit User Guide chapter for more information.

Since
2.6