You can open the samples inside an IDE using the IntelliJ native importer or Eclipse Buildship.

This sample shows how to test Java projects using JUnit 4 in Gradle.

Applications can be configured as follow:

application/build.gradle
plugins {
    id 'application'
}

repositories {
    jcenter()
}

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

application {
    mainClassName = 'org.gradle.sample.Main'
}
application/build.gradle.kts
plugins {
    application
}

repositories {
    jcenter()
}

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

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

Libraries can be configured as follow:

library/build.gradle
plugins {
    id 'java-library'
}

repositories {
    jcenter()
}

dependencies {
    testImplementation 'junit:junit:4.12'
}
library/build.gradle.kts
plugins {
    `java-library`
}

repositories {
    jcenter()
}

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

To test the projects:

$ ./gradlew test

BUILD SUCCESSFUL in 7s
7 actionable tasks: 7 executed

For more information, see Testing in Java project chapter. You can also get started quickly using the Build Init Plugin.