# Testing with JUnit5 Sample

version 6.5

- 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 test Java projects with JUnit5 in Gradle.

For applications:

application/build.gradle

    plugins {
        id 'application'
    }

    dependencies {
        implementation project(':utilities')
        testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.1'
        testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
    }

    application {
        mainClass = 'org.gradle.sample.app.Main'
    }

    test {
        useJUnitPlatform()
    }

application/build.gradle.kts

    plugins {
        application
    }

    dependencies {
        implementation(project(":utilities"))
        testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.1")
        testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
    }

    application {
        mainClass.set("org.gradle.sample.app.Main")
    }

    tasks.named<Test>("test") {
        useJUnitPlatform()
    }

For libraries:

list/build.gradle

    plugins {
        id 'java-library'
    }

    dependencies {
        testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.1'
        testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
    }

    test {
        useJUnitPlatform()
    }

list/build.gradle.kts

    plugins {
        `java-library`
    }

    dependencies {
        testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.1")
        testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
    }

    tasks.named<Test>("test") {
        useJUnitPlatform()
    }

Running the tests:

    $ ./gradlew test

    BUILD SUCCESSFUL
    5 actionable tasks: 5 executed

For more information, see Testing in Java project chapter.

You can also generate this project locally using `gradle init`.