|
1 | 1 | import org.apache.tools.ant.util.TeeOutputStream
|
2 | 2 |
|
3 |
| -apply plugin: 'org.junit.platform.gradle.plugin' |
4 |
| - |
5 |
| -ext { |
6 |
| - junitJupiterVersion = '5.0.0-M2' |
7 |
| -} |
8 |
| - |
9 | 3 | dependencies {
|
10 |
| - testCompile "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}" |
11 |
| - testRuntime "org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}" |
| 4 | + testImplementation(platform('org.junit:junit-bom:5.7.0')) |
| 5 | + testImplementation('org.junit.jupiter:junit-jupiter') |
12 | 6 | }
|
13 | 7 |
|
14 |
| -junitPlatform { |
15 |
| - platformVersion '1.0.0-M2' |
16 |
| - includeClassNamePattern '.*' |
| 8 | +test { |
| 9 | + useJUnitPlatform() |
| 10 | + testLogging { |
| 11 | + events "passed", "skipped", "failed" |
| 12 | + } |
17 | 13 | }
|
18 | 14 |
|
19 | 15 | /* NEW: (REQUIRES CODE REWRITES IN BOOK AND TEST CODE)
|
@@ -45,14 +41,28 @@ junitPlatform {
|
45 | 41 | JUnit 5's junitPlatformTest runs as a "javaExec" rather than a "test",
|
46 | 42 | so we can't hook into the before/after test behavior.
|
47 | 43 | */
|
48 |
| -tasks.findByPath(":$name:junitPlatformTest").configure { |
| 44 | +tasks.findByPath(":$name:test").configure { |
49 | 45 | File testDir = file("tests")
|
50 | 46 | if(testDir.exists()) {
|
51 | 47 | File outFile = new File(testDir, 'report.txt')
|
| 48 | + |
| 49 | + Writer taskOutput |
| 50 | + |
52 | 51 | doFirst {
|
53 |
| - standardOutput = new TeeOutputStream(new FileOutputStream(outFile, true), System.out) |
| 52 | + taskOutput = project.file(outFile).newWriter() |
54 | 53 | }
|
| 54 | + |
| 55 | + testLogging.showStandardStreams = true |
| 56 | + |
| 57 | + onOutput { descriptor, event -> |
| 58 | + taskOutput.append(event.message) |
| 59 | + } |
| 60 | + |
55 | 61 | doLast {
|
| 62 | + // WARNING: if the task fails, this won't be executed and the file remains open. |
| 63 | + // The memory cache version doesn't have this problem. |
| 64 | + taskOutput.close() |
| 65 | + |
56 | 66 | if(outFile.size() == 0)
|
57 | 67 | outFile.delete()
|
58 | 68 | else if(outFile.text.contains("0 tests found"))
|
|
0 commit comments