Skip to content

Commit 22b4982

Browse files
author
bfrasure
committed
Store test output in $projectName/tests/report.txt
1 parent 543409a commit 22b4982

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

build.gradle

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,26 @@ subprojects {
263263
}
264264
}
265265
task run(dependsOn: createdTasks)
266+
267+
/* Store test output in $projectName/tests
268+
JUnit 5's junitPlatformTest runs as a "javaExec" rather than a "test",
269+
so we can't hook into the before/after test behavior.
270+
*/
271+
tasks.findByPath(":$name:junitPlatformTest").configure{
272+
File testDir = new File(project.name + "/tests")
273+
if ( testDir.exists() ) {
274+
File outFile = new File(testDir, 'report.txt')
275+
doFirst{
276+
standardOutput = new TeeOutputStream(new FileOutputStream(outFile, true), System.out)
277+
}
278+
doLast {
279+
if(outFile.size() == 0)
280+
outFile.delete()
281+
else if(outFile.text.contains("0 tests found"))
282+
outFile.delete()
283+
}
284+
}
285+
}
266286
}
267287

268288
project(':validating') {

0 commit comments

Comments
 (0)