Revisit metrics and tracing test properties

This commit renames 'spring.test.metrics.auto-configure' and
'spring.test.tracing.auto-configure' for consistency with the non-test
properties. It also adds a configuration metadata entry for
'spring.test.observability.auto-configure' that's superseded by these
two properties.

Closes gh-47776
This commit is contained in:
Stéphane Nicoll
2025-10-23 11:18:53 +02:00
parent 58d8b938ef
commit ffc822d852
7 changed files with 22 additions and 17 deletions
@@ -6,6 +6,13 @@
"description": "Whether auto-configuration of JSON testers is enabled.",
"defaultValue": "true"
},
{
"name": "spring.test.observability.auto-configure",
"deprecation": {
"reason": "Superseded by 'spring.test.metrics.export' and 'spring.test.tracing.export'.",
"level": "error"
}
},
{
"name": "spring.test.print-condition-evaluation-report",
"type": "java.lang.Boolean",
@@ -41,8 +41,7 @@ import org.springframework.test.context.TestContextAnnotationUtils;
*/
class MetricsContextCustomizerFactory implements ContextCustomizerFactory {
// TODO spring.test.metrics.export?
static final String AUTO_CONFIGURE_PROPERTY = "spring.test.metrics.auto-configure";
static final String AUTO_CONFIGURE_PROPERTY = "spring.test.metrics.export";
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
@@ -1,9 +1,9 @@
{
"properties": [
{
"name": "spring.test.metrics.auto-configure",
"name": "spring.test.metrics.export",
"type": "java.lang.Boolean",
"description": "Whether metrics should be auto-configured in tests.",
"description": "Whether metrics export should be auto-configured in tests.",
"defaultValue": false
}
]
@@ -94,18 +94,18 @@ class MetricsContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(NoAnnotation.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.metrics.auto-configure", "true");
environment.setProperty("spring.test.metrics.export", "true");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatMetricsAreEnabled(context);
}
@Test
void metricsCanBeDisabledViaProperty() {
void metricsExportCanBeDisabledViaProperty() {
ContextCustomizer customizer = createContextCustomizer(NoAnnotation.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.metrics.auto-configure", "false");
environment.setProperty("spring.test.metrics.export", "false");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatMetricsAreDisabled(context);
@@ -116,7 +116,7 @@ class MetricsContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(MetricsExportEnabled.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.metrics.auto-configure", "false");
environment.setProperty("spring.test.metrics.export", "false");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatMetricsAreEnabled(context);
@@ -127,7 +127,7 @@ class MetricsContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(MetricsExportDisabled.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.metrics.auto-configure", "true");
environment.setProperty("spring.test.metrics.export", "true");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatMetricsAreDisabled(context);
@@ -41,8 +41,7 @@ import org.springframework.test.context.TestContextAnnotationUtils;
*/
class TracingContextCustomizerFactory implements ContextCustomizerFactory {
// TODO spring.test.tracing.export?
static final String AUTO_CONFIGURE_PROPERTY = "spring.test.tracing.auto-configure";
static final String AUTO_CONFIGURE_PROPERTY = "spring.test.tracing.export";
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
@@ -1,9 +1,9 @@
{
"properties": [
{
"name": "spring.test.tracing.auto-configure",
"name": "spring.test.tracing.export",
"type": "java.lang.Boolean",
"description": "Whether tracing should be auto-configured in tests.",
"description": "Whether tracing export should be auto-configured in tests.",
"defaultValue": false
}
]
@@ -93,7 +93,7 @@ class TracingContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(NoAnnotation.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.tracing.auto-configure", "true");
environment.setProperty("spring.test.tracing.export", "true");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatTracingExportIsEnabled(context);
@@ -104,7 +104,7 @@ class TracingContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(NoAnnotation.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.tracing.auto-configure", "false");
environment.setProperty("spring.test.tracing.export", "false");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatTracingExportIsDisabled(context);
@@ -115,7 +115,7 @@ class TracingContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(TracingExportEnabled.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.tracing.auto-configure", "false");
environment.setProperty("spring.test.tracing.export", "false");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatTracingExportIsEnabled(context);
@@ -126,7 +126,7 @@ class TracingContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(TracingExportDisabled.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.tracing.auto-configure", "true");
environment.setProperty("spring.test.tracing.export", "true");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatTracingExportIsDisabled(context);