Skip to content

Commit 52ca83c

Browse files
committed
build(test): reduce test output noise with context-aware verbosity
Make test logging conditional on invocation context: `gradle build` produces quiet output (pass/fail only), while `gradle test` shows verbose output with stdout/stderr and full stack traces for debugging. - Add JVM args to suppress Mockito self-attach and CDS warnings - Create logback-test.xml to eliminate /opt/app/logs file appender errors - Reduce test log levels from DEBUG to INFO/WARN in application-test.properties - Remove redundant System.setProperty for security DEBUG logging - Apply same conditional logging to registerJdkTestTask Reduces `gradle build` output from ~7,400 lines to ~1,100 lines.
1 parent ee0aed0 commit 52ca83c

4 files changed

Lines changed: 40 additions & 10 deletions

File tree

build.gradle

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,27 @@ tasks.named('bootJar') {
106106

107107
test {
108108
useJUnitPlatform()
109+
jvmArgs '-XX:+EnableDynamicAgentLoading', '-Xshare:off'
109110
// Enable parallel execution for faster test runs
110111
systemProperty 'junit.jupiter.execution.parallel.enabled', 'true'
111112
systemProperty 'junit.jupiter.execution.parallel.mode.default', 'concurrent'
112113
systemProperty 'junit.jupiter.execution.parallel.mode.classes.default', 'concurrent'
113114
// Use available CPU cores - 1 for parallel execution
114115
systemProperty 'junit.jupiter.execution.parallel.config.strategy', 'dynamic'
115116
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
116-
testLogging {
117-
events "PASSED", "FAILED", "SKIPPED"
118-
exceptionFormat "full"
119-
showStandardStreams true
120-
}
117+
118+
def isExplicitTest = gradle.startParameter.taskNames.any {
119+
it == 'test' || it == 'testAll' || it.startsWith('testJdk')
120+
}
121+
testLogging {
122+
events "PASSED", "FAILED", "SKIPPED"
123+
if (isExplicitTest) {
124+
exceptionFormat "full"
125+
showStandardStreams true
126+
} else {
127+
exceptionFormat "short"
128+
}
129+
}
121130
}
122131

123132
tasks.named('jar') {
@@ -140,14 +149,25 @@ def registerJdkTestTask(name, jdkVersion) {
140149
testClassesDirs = sourceSets.test.output.classesDirs
141150
classpath = sourceSets.test.runtimeClasspath
142151
useJUnitPlatform()
152+
jvmArgs '-XX:+EnableDynamicAgentLoading', '-Xshare:off'
143153
// Enable parallel execution for JDK-specific tests
144154
systemProperty 'junit.jupiter.execution.parallel.enabled', 'true'
145155
systemProperty 'junit.jupiter.execution.parallel.mode.default', 'concurrent'
146156
systemProperty 'junit.jupiter.execution.parallel.mode.classes.default', 'concurrent'
147157
systemProperty 'junit.jupiter.execution.parallel.config.strategy', 'dynamic'
148158
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
159+
160+
def isExplicitTest = gradle.startParameter.taskNames.any {
161+
it == 'test' || it == 'testAll' || it.startsWith('testJdk')
162+
}
149163
testLogging {
150164
events "PASSED", "FAILED", "SKIPPED"
165+
if (isExplicitTest) {
166+
exceptionFormat "full"
167+
showStandardStreams true
168+
} else {
169+
exceptionFormat "short"
170+
}
151171
}
152172
doFirst {
153173
println("Running tests with JDK $jdkVersion")

src/test/java/com/digitalsanctuary/spring/user/test/config/BaseTestConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public TestPropertySourcesConfigurer() {
101101
System.setProperty("spring.profiles.active", "test");
102102
System.setProperty("spring.jpa.hibernate.ddl-auto", "create-drop");
103103
System.setProperty("spring.datasource.initialization-mode", "always");
104-
System.setProperty("logging.level.org.springframework.security", "DEBUG");
105104
}
106105
}
107106
}

src/test/resources/application-test.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ spring.jpa.show-sql=false
1414
spring.jpa.properties.hibernate.format_sql=true
1515

1616
# Logging
17-
logging.level.com.digitalsanctuary.spring.user=DEBUG
18-
logging.level.org.springframework.security=DEBUG
19-
logging.level.org.springframework.web=DEBUG
20-
logging.level.sql=DEBUG
17+
logging.level.com.digitalsanctuary.spring.user=INFO
18+
logging.level.org.springframework.security=WARN
19+
logging.level.org.springframework.web=WARN
20+
logging.level.sql=WARN
2121

2222
# Mail Configuration (using mock)
2323
spring.mail.host=localhost
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
6+
</encoder>
7+
</appender>
8+
<root level="WARN">
9+
<appender-ref ref="CONSOLE" />
10+
</root>
11+
</configuration>

0 commit comments

Comments
 (0)