I am moving tests to junit5 that are going to be run with Gradle. In a project I work with there are unit tests and some specific tests that must be run on demand (from particul
Define a new configuration, depend on junit-platform-console-standalone
artifact and configure the console launcher to your needs. Like:
configurations {
standalone
}
dependencies {
standalone 'org.junit.platform:junit-platform-console-standalone:1.0.0-SNAPSHOT'
}
task downloadJUnitPlatformStandalone(type: Copy) {
from configurations.standalone
into "$buildDir/junit-platform-standalone"
eachFile { println " (standalone) -> " + it.file.name }
}
task runJUnitPlatformStandalone(type: JavaExec, dependsOn: downloadJUnitPlatformStandalone) {
jvmArgs '-ea'
jvmArgs '-Djava.util.logging.config.file=src/test/logging.properties'
classpath = fileTree(dir: "$buildDir/junit-platform-standalone", include: '*.jar') + project.sourceSets.test.runtimeClasspath
main 'org.junit.platform.console.ConsoleLauncher'
args += '--scan-class-path'
args += '--disable-ansi-colors'
args += '--details=tree'
args += "--reports-dir=$project.testReportDir"
}
test.dependsOn runJUnitPlatformStandalone
Source junit-platform-standalone.gradle or alternate (Jupiter-only) dependencies jupiter.gradle.
Without own configuration and download: https://discuss.gradle.org/t/junit-5-jupiter-platform-snapshot-console-launcher-task/19773/2