1515 * limitations under the License.
1616 */
1717
18+ import java.util.regex.Pattern
1819import org.apache.lucene.gradle.ErrorReportingTestListener
1920
2021// Display all failed tests at the end of the build.
@@ -33,11 +34,28 @@ allprojects {
3334
3435 afterTest { desc , result ->
3536 if (result. resultType == TestResult.ResultType . FAILURE ) {
37+ // check if it's a constructor or a before/after class hook that failed.
38+ def qTestName
39+ if (desc. name == " classMethod" ) {
40+ qTestName = desc. className
41+ } else {
42+ qTestName = " ${ desc.className} .${ desc.name} "
43+ }
44+
45+ def randomizationParameters = " "
46+ def p = Pattern . compile(/ .+ (?<params>[{].*[}])$/ )
47+ def matcher = p. matcher(qTestName)
48+ if (matcher. matches()) {
49+ randomizationParameters = matcher. group(" params" )
50+ qTestName = qTestName. replace(randomizationParameters, " " ). trim()
51+ }
52+
3653 failedTests << [
37- " name" : " ${ desc.className} .${ desc.name} " ,
54+ " name" : qTestName,
55+ " randomizationParameters" : randomizationParameters,
3856 " project" : " ${ test.project.path} " ,
3957 " output" : file(" ${ testOutputsDir} /${ ErrorReportingTestListener.getOutputLogName(desc.parent)} " ),
40- " reproduce" : " gradlew ${ project.path} :test --tests \" ${ desc.className } . ${ desc.name } \" ${ reproLine} "
58+ " reproduce" : " gradlew ${ project.path} :test --tests \" ${ qTestName } \" ${ reproLine} "
4159 ]
4260 }
4361 }
@@ -62,11 +80,14 @@ gradle.buildFinished { result ->
6280 .sort { a , b -> b. project. compareTo(a. project) }
6381 .collect { e ->
6482 String . format(Locale . ROOT ,
65- " - %s (%s)\n Test output: %s\n Reproduce with: %s\n " ,
66- e. name, e. project, e. output, e. reproduce)
83+ " - %s (%s)%s\n Test output: %s\n Reproduce with: %s\n " ,
84+ e. name, e. project,
85+ e. containsKey(" randomizationParameters" ) &&
86+ ! e. randomizationParameters. isBlank() ? " \n Context parameters: ${ e.randomizationParameters} " : " " ,
87+ e. output, e. reproduce)
6788 }
6889 .join(" \n " )
6990
70- logger. error(" \n ERROR: The following test(s) have failed:\n ${ formatted } " )
91+ logger. error(" \n ERROR: The following {} failed:\n\n {} " , failedTests . size() == 1 ? " test has " : " tests have " , formatted )
7192 }
7293}
0 commit comments