@@ -66,13 +66,23 @@ public class YamlTestExtension implements TestTemplateInvocationContextProvider,
66
66
private List <ExternalServer > servers ;
67
67
@ Nullable
68
68
private final String clusterFile ;
69
+ private final boolean includeMethodInDescriptions ;
69
70
70
71
public YamlTestExtension () {
71
- this . clusterFile = null ; // it will get it from the environment
72
+ this ( null , false );
72
73
}
73
74
74
- public YamlTestExtension (@ Nullable final String clusterFile ) {
75
+ /**
76
+ * Create a new extension with some configuration.
77
+ * @param clusterFile a custom cluster file to use, or {@code null} to inherit it from the environment, namely
78
+ * {@code FDB_CLUSTER_FILE}.
79
+ * @param includeMethodInDescriptions Set this to {@code true} if publishing test results to something that cannot
80
+ * handle complex test hierarchies. In the record layer we maintain the full hierarchy in the output, so this is not
81
+ * necessary, but if integrating some other tools this might be necessary.
82
+ */
83
+ public YamlTestExtension (@ Nullable final String clusterFile , final boolean includeMethodInDescriptions ) {
75
84
this .clusterFile = clusterFile ;
85
+ this .includeMethodInDescriptions = includeMethodInDescriptions ;
76
86
}
77
87
78
88
@ Override
@@ -184,34 +194,36 @@ public boolean supportsTestTemplate(final ExtensionContext context) {
184
194
@ Override
185
195
public Stream <TestTemplateInvocationContext > provideTestTemplateInvocationContexts (final ExtensionContext context ) {
186
196
final var testClass = context .getRequiredTestClass ();
197
+ final var testMethod = context .getRequiredTestMethod ();
187
198
if (testClass .getAnnotation (MaintainYamlTestConfig .class ) != null ) {
188
199
final var annotation = testClass .getAnnotation (MaintainYamlTestConfig .class );
189
- return provideInvocationContextsForMaintenance (annotation );
200
+ return provideInvocationContextsForMaintenance (annotation , testMethod . getName () );
190
201
}
191
- final var testMethod = context .getRequiredTestMethod ();
192
202
if (testMethod .getAnnotation (ExcludeYamlTestConfig .class ) != null ) {
193
203
// excluded tests are still included as configs so that they show up in the test run as skipped, rather than
194
204
// just not being there. This may waste some resources if all the tests being run exclude a config that has
195
205
// expensive @BeforeAll.
196
206
final var annotation = testMethod .getAnnotation (ExcludeYamlTestConfig .class );
197
207
return testConfigs
198
208
.stream ()
199
- .map (config -> new Context (config , annotation .reason (), annotation .value ()));
209
+ .map (config -> new Context (config , annotation .reason (), annotation .value (),
210
+ includeMethodInDescriptions , testMethod .getName ()));
200
211
} else if (testMethod .getAnnotation (MaintainYamlTestConfig .class ) != null ) {
201
212
final var annotation =
202
213
testMethod .getAnnotation (MaintainYamlTestConfig .class );
203
- return provideInvocationContextsForMaintenance (annotation );
214
+ return provideInvocationContextsForMaintenance (annotation , testMethod . getName () );
204
215
}
205
216
return testConfigs
206
217
.stream ()
207
- .map (config -> new Context (config , "" , null ));
218
+ .map (config -> new Context (config , "" , null , includeMethodInDescriptions , testMethod . getName () ));
208
219
}
209
220
210
- private Stream <TestTemplateInvocationContext > provideInvocationContextsForMaintenance (@ Nonnull final MaintainYamlTestConfig annotation ) {
221
+ private Stream <TestTemplateInvocationContext > provideInvocationContextsForMaintenance (
222
+ @ Nonnull final MaintainYamlTestConfig annotation , @ Nonnull final String methodName ) {
211
223
return maintainConfigs
212
224
.stream ()
213
225
.map (config -> new Context (config , "maintenance not needed" ,
214
- Objects .requireNonNull (annotation .value ())));
226
+ Objects .requireNonNull (annotation .value ()), includeMethodInDescriptions , methodName ));
215
227
}
216
228
217
229
/**
@@ -225,17 +237,27 @@ private static class Context implements TestTemplateInvocationContext {
225
237
private final String excludedReason ;
226
238
@ Nullable
227
239
private final YamlTestConfigFilters configFilters ;
240
+ private final boolean includeMethodInDescriptions ;
241
+ @ Nonnull
242
+ private final String methodName ;
228
243
229
244
public Context (@ Nonnull final YamlTestConfig config , @ Nonnull final String excludedReason ,
230
- @ Nullable final YamlTestConfigFilters configFilters ) {
245
+ @ Nullable final YamlTestConfigFilters configFilters ,
246
+ final boolean includeMethodInDescriptions , @ Nonnull final String methodName ) {
231
247
this .config = config ;
232
248
this .excludedReason = excludedReason ;
233
249
this .configFilters = configFilters ;
250
+ this .includeMethodInDescriptions = includeMethodInDescriptions ;
251
+ this .methodName = methodName ;
234
252
}
235
253
236
254
@ Override
237
255
public String getDisplayName (int invocationIndex ) {
238
- return config .toString ();
256
+ if (includeMethodInDescriptions ) {
257
+ return methodName + "(" + config + ")" ;
258
+ } else {
259
+ return config .toString ();
260
+ }
239
261
}
240
262
241
263
@ Override
0 commit comments