1+ import java.util.concurrent.ConcurrentHashMap
12/*
23 * Copyright 2002-2020 the original author or authors.
34 *
@@ -51,6 +52,9 @@ if (project.hasProperty("springFrameworkVersion")) {
5152if (project. hasProperty(" reactorVersion" )) {
5253 ext[' reactor-bom.version' ] = ext. reactorVersion
5354}
55+ if (! project. hasProperty(" onlyShowStandardStreamsOnTestFailure" )) {
56+ ext. onlyShowStandardStreamsOnTestFailure = false
57+ }
5458
5559apply plugin : " io.spring.nohttp"
5660
@@ -69,6 +73,59 @@ configure(allprojects) {
6973 if (subproject. description == null || subproject. description. isEmpty()) {
7074 throw new InvalidUserDataException (" A project description is required for publishing to maven central" )
7175 }
76+
77+ tasks. withType(Test ). forEach { Test task ->
78+ task. with {
79+ // enable JUnit 5
80+ useJUnitPlatform()
81+ scanForTestClasses = true
82+ group = " verification"
83+
84+ testLogging {
85+ exceptionFormat = " full"
86+ events = [" passed" , " skipped" , " failed" ]
87+ showStandardStreams = ! project. onlyShowStandardStreamsOnTestFailure
88+ }
89+
90+ if (project. onlyShowStandardStreamsOnTestFailure) {
91+ Map<String , StringBuilder > testOutput = new ConcurrentHashMap<> ()
92+
93+ onOutput { TestDescriptor descriptor , TestOutputEvent event ->
94+ testOutput. compute(descriptor. displayName, { k , v ->
95+ v == null ? new StringBuilder (event. message) : v. append(event. message)
96+ })
97+ }
98+
99+ afterTest { TestDescriptor descriptor , TestResult result ->
100+ if (result. resultType == TestResult.ResultType . FAILURE && testOutput. containsKey(descriptor. displayName)) {
101+ logger. lifecycle(" \n\n ${ testOutput.get(descriptor.displayName)} " )
102+ testOutput. remove(descriptor. displayName)
103+ }
104+ }
105+ }
106+
107+ // print failed tests after the execution
108+ def failedTests = []
109+ afterTest { test , result ->
110+ if (result. resultType == TestResult.ResultType . FAILURE ) {
111+ failedTests << test
112+ }
113+ }
114+
115+ // create a summary after the execution
116+ afterSuite { desc , result ->
117+ if (! desc. parent) {
118+ println " \n Test result: ${ result.resultType} "
119+ println " Test summary: ${ result.testCount} tests, " +
120+ " ${ result.successfulTestCount} succeeded, " +
121+ " ${ result.failedTestCount} failed, " +
122+ " ${ result.skippedTestCount} skipped"
123+
124+ failedTests. each { test -> println " FAILED test: ${ test.className} > ${ test.name} " }
125+ }
126+ }
127+ }
128+ }
72129 }
73130
74131 apply from : " ${ rootProject.projectDir} /publish-maven.gradle"
@@ -116,42 +173,6 @@ configure(allprojects - [project(":spring-cloud-app-broker-docs")]) {
116173 ruleSetFiles = files(" ${ project.rootDir} /src/pmd/pmdTestRuleSet.xml" )
117174 source = " src/test/java"
118175 }
119-
120- test {
121- // enable JUnit 5
122- useJUnitPlatform()
123-
124- testLogging {
125- // display all the events
126- events ' PASSED' , ' FAILED' , ' SKIPPED'
127- // display stdout and stderr
128- showStandardStreams = true
129- }
130-
131- // create a summary after the execution
132- afterSuite { desc , result ->
133- if (! desc. parent) {
134- println " \n Test result: ${ result.resultType} "
135- println " Test summary: ${ result.testCount} tests, " +
136- " ${ result.successfulTestCount} succeeded, " +
137- " ${ result.failedTestCount} failed, " +
138- " ${ result.skippedTestCount} skipped"
139- }
140- }
141-
142- // print failed tests after the execution
143- def failedTests = []
144-
145- afterTest { test , result ->
146- if (result. resultType == TestResult.ResultType . FAILURE ) {
147- failedTests << test
148- }
149- }
150-
151- afterSuite {
152- failedTests. each { test -> println " FAILED test: ${ test.className} > ${ test.name} " }
153- }
154- }
155176}
156177
157178subprojects {
0 commit comments