Skip to content

Commit daa1316

Browse files
committed
[#2492] fix(hr test container local plugin): remove replace test with custom task, configure it instead
1 parent f41d77c commit daa1316

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

local-build-plugins/src/main/groovy/hr-test-containers.gradle

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,53 @@ dbs.each { db ->
1313
}
1414
}
1515

16-
// replace default task 'test' with custom TestDbTask to always configure with cache safe task
17-
tasks.replace( "test", TestDbTask ).configure {
18-
dbName = project.findProperty( "db" ) ?: "PostgreSQL"
19-
dockerEnabled = project.hasProperty( "docker" )
20-
if ( project.hasProperty( "includeTests" ) ) {
21-
includeTests = project.property( "includeTests" )
16+
// configure default task 'test' with same config of TestDbTask, with cache safe
17+
tasks.named( "test", Test ).configure { t ->
18+
def dbName = providers.gradleProperty( "db" ).orElse( "PostgreSQL" )
19+
def dockerEnabled = providers.gradleProperty( "docker" ).isPresent()
20+
def includeTests = providers.gradleProperty( "includeTests" ).orNull
21+
def showStandardStreams = providers.gradleProperty( "showStandardOutput" ).isPresent()
22+
23+
t.systemProperty( "db", dbName.get() )
24+
t.systemProperty( "docker", dockerEnabled ? "true" : "false" )
25+
t.systemProperty( "org.hibernate.reactive.common.InternalStateAssertions.ENFORCE", "true" )
26+
27+
if ( includeTests ) {
28+
t.filter { f -> f.includeTestsMatching( includeTests ) }
29+
}
30+
31+
t.defaultCharacterEncoding = "UTF-8"
32+
t.useJUnitPlatform()
33+
t.testLogging {
34+
it.showStandardStreams = showStandardStreams
35+
it.showStackTraces = true
36+
it.exceptionFormat = 'full'
37+
it.displayGranularity = 1
38+
it.events = ['PASSED', 'FAILED', 'SKIPPED']
2239
}
23-
description = "Default test task using TestDbTask"
40+
41+
t.addTestListener( new TestListener() {
42+
void beforeSuite(TestDescriptor suite) {
43+
/* Do nothing */
44+
}
45+
46+
void beforeTest(TestDescriptor testDescriptor) {
47+
/* Do nothing */
48+
}
49+
50+
void afterTest(TestDescriptor testDescriptor, TestResult result) {
51+
/* Do nothing */
52+
}
53+
54+
// Add afterSuite hook
55+
void afterSuite(TestDescriptor desc, TestResult result) {
56+
if ( !desc.parent ) {
57+
def output = "${dbName.get()} results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
58+
def line = '-' * (output.length() + 1)
59+
logger.lifecycle( "\n${line}\n${output}\n${line}" )
60+
}
61+
}
62+
} )
2463
}
2564

2665
// configure all testDbTask with docker and filter test

0 commit comments

Comments
 (0)