Skip to content

Commit 8d727de

Browse files
committed
fix(junit): Apply class level configuration at @beforeeach level
So child classes can benefits from class level configs and we can configure the tracer for example
1 parent 23194c7 commit 8d727de

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

utils/junit-utils/src/main/java/datadog/trace/junit/utils/config/WithConfigExtension.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public void beforeAll(ExtensionContext context) {
8787
if (originalSystemProperties == null) {
8888
saveProperties();
8989
}
90+
// Apply class-level @WithConfig so config is available before @BeforeAll methods
91+
applyClassLevelConfig(context);
92+
if (isConfigInstanceModifiable) {
93+
rebuildConfig();
94+
}
9095
}
9196

9297
@Override
@@ -116,8 +121,12 @@ public void afterAll(ExtensionContext context) {
116121
}
117122
}
118123

119-
private void applyDeclaredConfig(ExtensionContext context) {
120-
// Class-level @WithConfig annotations
124+
private static void applyDeclaredConfig(ExtensionContext context) {
125+
applyClassLevelConfig(context);
126+
applyMethodLevelConfig(context);
127+
}
128+
129+
private static void applyClassLevelConfig(ExtensionContext context) {
121130
// Walk the entire class hierarchy so annotations on superclasses are applied
122131
// (topmost first, then subclass overrides)
123132
Class<?> testClass = context.getRequiredTestClass();
@@ -132,6 +141,9 @@ private void applyDeclaredConfig(ExtensionContext context) {
132141
applyConfig(cfg);
133142
}
134143
}
144+
}
145+
146+
private static void applyMethodLevelConfig(ExtensionContext context) {
135147
// Method-level @WithConfig annotations (supports composed/meta-annotations)
136148
context
137149
.getTestMethod()

0 commit comments

Comments
 (0)