OnJava8-Examples/gradle/junit-jupiter.gradle

73 lines
1.7 KiB
Groovy
Raw Normal View History

import org.apache.tools.ant.util.TeeOutputStream
dependencies {
2020-10-06 12:05:43 -06:00
testImplementation(platform('org.junit:junit-bom:5.7.0'))
testImplementation('org.junit.jupiter:junit-jupiter')
}
2020-10-06 12:05:43 -06:00
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
2016-12-21 14:18:56 -08:00
/* NEW: (REQUIRES CODE REWRITES IN BOOK AND TEST CODE)
-> http://junit.org/junit5/docs/current/user-guide/
ext {
junitJupiterVersion = '5.0.0-M3'
}
dependencies {
testCompile "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}"
testRuntime "org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}"
}
junitPlatform {
platformVersion '1.0.0-M3'
filters {
packages {
2016-12-30 22:22:39 -08:00
exclude 'collectiontopics.jmh'
2016-12-21 14:18:56 -08:00
}
includeClassNamePattern '.*'
}
}
*/
/* Store test output in $projectName/tests
JUnit 5's junitPlatformTest runs as a "javaExec" rather than a "test",
so we can't hook into the before/after test behavior.
*/
2020-10-06 12:05:43 -06:00
tasks.findByPath(":$name:test").configure {
File testDir = file("tests")
if(testDir.exists()) {
File outFile = new File(testDir, 'report.txt')
2020-10-06 12:05:43 -06:00
Writer taskOutput
doFirst {
2020-10-06 12:05:43 -06:00
taskOutput = project.file(outFile).newWriter()
}
2020-10-06 12:05:43 -06:00
testLogging.showStandardStreams = true
onOutput { descriptor, event ->
taskOutput.append(event.message)
}
doLast {
2020-10-06 12:05:43 -06:00
// WARNING: if the task fails, this won't be executed and the file remains open.
// The memory cache version doesn't have this problem.
taskOutput.close()
if(outFile.size() == 0)
outFile.delete()
else if(outFile.text.contains("0 tests found"))
outFile.delete()
}
}
2016-12-21 11:07:03 -08:00
}