# Additional test types Sample

version 6.1

- Groovy DSL

- Kotlin DSL

| You can open this sample inside an IDE using the IntelliJ native importer or Eclipse Buildship.

This sample shows how to add additional test types to a JVM project in Gradle. Your project may have many different kinds of tests—​unit tests, integration tests, functional tests, etc. A JVM project in Gradle has a single `Test` task, but other tasks can be added to represent each of these test types.

In this sample, we are testing Java projects with JUnit4; however, this applies to other JVM languages as well.

For applications:

application/build.gradle

    plugins {
        id 'application'
    }

    dependencies {
        implementation project(':list')
        implementation project(':utilities')
        testImplementation 'junit:junit:4.12'
    }

    application {
        mainClassName = 'org.gradle.sample.Main'
    }

    sourceSets {
        integrationTest {
            compileClasspath += sourceSets.main.output
            runtimeClasspath += sourceSets.main.output
        }
    }

    configurations {
        integrationTestImplementation.extendsFrom implementation
        integrationTestRuntimeOnly.extendsFrom runtimeOnly
    }

    dependencies {
        integrationTestImplementation 'junit:junit:4.12'
    }

    def integrationTest = tasks.register('integrationTest', Test) {
        description = 'Runs integration tests.'
        group = 'verification'

        testClassesDirs = sourceSets.integrationTest.output.classesDirs
        classpath = sourceSets.integrationTest.runtimeClasspath
        shouldRunAfter('test')
    }

    tasks.named('check') { dependsOn(integrationTest) }

application/build.gradle.kts

    plugins {
        application
    }

    dependencies {
        implementation(project(":list"))
        implementation(project(":utilities"))
        testImplementation("junit:junit:4.12")
    }

    application {
        mainClassName = "org.gradle.sample.Main"
    }

    sourceSets {
        create("integrationTest") {
            compileClasspath += sourceSets.main.get().output
            runtimeClasspath += sourceSets.main.get().output
        }
    }

    val integrationTestImplementation by configurations.getting {
        extendsFrom(configurations.implementation.get())
    }

    configurations["integrationTestRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get())

    dependencies {
        integrationTestImplementation("junit:junit:4.12")
    }

    val integrationTest = tasks.register<Test>("integrationTest") {
        description = "Runs integration tests."
        group = "verification"

        testClassesDirs = sourceSets["integrationTest"].output.classesDirs
        classpath = sourceSets["integrationTest"].runtimeClasspath
        shouldRunAfter("test")
    }

    tasks.check { dependsOn(integrationTest) }

For libraries:

list/build.gradle

    plugins {
        id 'java-library'
    }

    dependencies {
        testImplementation 'junit:junit:4.12'
    }

    sourceSets {
        integrationTest {
            compileClasspath += sourceSets.main.output
            runtimeClasspath += sourceSets.main.output
        }
    }

    configurations {
        integrationTestImplementation.extendsFrom implementation
        integrationTestRuntimeOnly.extendsFrom runtimeOnly
    }

    dependencies {
        integrationTestImplementation 'junit:junit:4.12'
    }

    def integrationTest = tasks.register('integrationTest', Test) {
        description = 'Runs integration tests.'
        group = 'verification'

        testClassesDirs = sourceSets.integrationTest.output.classesDirs
        classpath = sourceSets.integrationTest.runtimeClasspath
        shouldRunAfter('test')
    }

    tasks.named('check') { dependsOn(integrationTest) }

list/build.gradle.kts

    plugins {
        `java-library`
    }

    dependencies {
        testImplementation("junit:junit:4.12")
    }

    sourceSets {
        create("integrationTest") {
            compileClasspath += sourceSets.main.get().output
            runtimeClasspath += sourceSets.main.get().output
        }
    }

    val integrationTestImplementation by configurations.getting {
        extendsFrom(configurations.implementation.get())
    }

    configurations["integrationTestRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get())

    dependencies {
        integrationTestImplementation("junit:junit:4.12")
    }

    val integrationTest = tasks.register<Test>("integrationTest") {
        description = "Runs integration tests."
        group = "verification"

        testClassesDirs = sourceSets["integrationTest"].output.classesDirs
        classpath = sourceSets["integrationTest"].runtimeClasspath
        shouldRunAfter("test")
    }

    tasks.check { dependsOn(integrationTest) }

These additional tests can be executed with the `integrationTest` task or as part of lifecycle `check`:

    $ ./gradlew check

    BUILD SUCCESSFUL in 2s
    11 actionable tasks: 11 executed

For more information, see section Configuring integration tests in the Testing in Java project chapter.