# Testing with JUnit4 Sample

version 6.3

- 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 JUnit4 in Gradle.

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'
    }

application/build.gradle.kts

    plugins {
        application
    }

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

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

For libraries:

list/build.gradle

    plugins {
        id 'java-library'
    }

    dependencies {
        testImplementation 'junit:junit:4.12'
    }

list/build.gradle.kts

    plugins {
        `java-library`
    }

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

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