Introduce 'spring.test.print-condition-evaluation-report' property

Add the `spring.test.print-condition-evaluation-report` property
to enable or disable the conditional evaluation report
when ApplicationContext fails to start.

See gh-45268

Signed-off-by: Dmytro Nosan <dimanosan@gmail.com>
This commit is contained in:
Dmytro Nosan
2025-04-09 18:48:59 +03:00
committed by Phillip Webb
parent e50da4fca2
commit 4ea54dae85
3 changed files with 56 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,7 +84,17 @@ class OnFailureConditionReportContextCustomizerFactory implements ContextCustomi
@Override
public void onApplicationEvent(ApplicationFailedEvent event) {
System.err.println(new ConditionEvaluationReportMessage(this.reportSupplier.get()));
if (shouldPrintReport(event.getApplicationContext())) {
System.err.println(new ConditionEvaluationReportMessage(this.reportSupplier.get()));
}
}
private static boolean shouldPrintReport(ConfigurableApplicationContext context) {
if (context == null) {
return true;
}
return context.getEnvironment()
.getProperty("spring.test.print-condition-evaluation-report", Boolean.class, true);
}
}

View File

@@ -17,6 +17,12 @@
"type": "java.lang.Boolean",
"description": "Whether observability should be auto-configured in tests.",
"defaultValue": "false"
},
{
"name": "spring.test.print-condition-evaluation-report",
"type": "java.lang.Boolean",
"description": "Whether the condition evaluation report should be printed when the ApplicationContext fails to start.",
"defaultValue": "true"
}
]
}