Structure

Conventions

Filesystem

Source directory layout
${projectDir} / src / gradleTest /  project1  / build.gradle
                                              / staged.testTwo.build.gradle
                                    project2  /
                                    project3  /

Each directory below gradleTest becomes a test as long as it contains a valid build file. A build file is considered valid if it is named build.gradle, build.gradle.kts, staged.<SOMETHING>.build.gradle or staged.<SOMETHING>.build.gradle.kts, where <SOMETHING> can be anythign chosen by the plugin author.

The test folder can have more than one build file in it as long as it is named as mentioned above. Each build file will be considered an individual test that is executed independently of the others.

Separate test directories are created for each test, but symlinks are created within the test directories back to the original source directories. In some cases this might result in files appearing in the source directory.

If this is not desired, then add the clean task to all your build execution scripts like this:

Cleaning before multi-test
tasks.register('runGradleTest') {
  dependsOn 'clean', 'someTask'
}

For testing, a folder is created for each gradle version to be tested and the projects are duplicated below the version folder. Each version’s testsuite is executed within a separate JVM.

Test directory layout
${buildDir} / gradleTest / ver 1  / project 1   (1)
                                  / project 2
                         / ver 2  / project 1
                                  / project 2
                         / manifest.txt  (2)
1 A folder is created for each version and each of the projects (test groups) are listed below
2 Custom classpath manifest is so configured.
Test layout for one test
... / ver1 / project1 / .gradle         (1)
                      / build           (2)
                      / build.gradle    (3)
                      / settings.gradle (4)
1 Project cachedir is sent here
2 It is recommended that the build directory not be changed and left as per default
3 build.gradle is required for the test to be executed. It must contain a task called runGradleTest.
4 If a test project does not have a settings.gradle file an empty one will be generated in the test folder

Gradle Entities

A GradleTest test set task called main will have the following associated entities:

Entity Type Description

gradleTest

Task

The actual GradleTest task of type Test.

gradleTestImplementation

Configuration

For building the generated test sources.

gradleTest

SourceSet

Manages internal generated source code

gradleTestRuntimeOnly

Configuration

Additional dependencies to pass to the underlying GradleRunner at runtime.

gradleTestRuntimeClasspath

Configuration

The actual classpath passe to the underlying GradleRunner.

gradleTestGenerator

Task

Generates test code that will be compiled and used to actually executed GradleTestKit-based code

compileGradleTestGroovy

Task

Compiles Groovy code generated by gradleTestGenerator

gradleTestClasses

Task

Associated classes task for compileGradleTestGroovy

gradleTestClasspathManifest

Task

This task is created if useCustomManifest() is declared.

Check lifecycle

New tasks are added to the check lifecycle when the org.ysb33r.gradletest plugin is applied. This is not the case for the base plugin.