0

What is a clean way to get a list of all my custom test method annotations of all to-be-executed test methods in a Jupiter BeforeAllCallback Extension?

The Extension shall collect setup data from these custom annotations on the test methods, and prepare the integration test before any of the test methods runs.

Before Jupiter 5.4, we had an ugly workaround in place to retrieve it via reflection from the ClassExtensionContext, set method "getTestDescriptor" accessible, and calling getChildren() on it. The returned set of TestMethodTestDescriptors will allow to collect our custom annotations...

Since Jupiter 5.4, ClassExtensionContext is package-private, and I would have to move my Extension to this very package org.junit.jupiter.engine.descriptor too, which would further uglify the workaround...

leo
  • 3,528
  • 3
  • 20
  • 19
  • Another workaround is to do reflection on the Test Class, `@BeforeAll ... this.getClass() ... find my custom annotations`. Although, it's difficult to determine the effectively executed test methods... Somewhat similar to https://stackoverflow.com/q/34098011/510583 – leo Sep 12 '19 at 15:07
  • ... and this can be implemented by using the jupiter `AnnotationUtils.findAnnotatedMethods()` class very easily, minus the `@Disabled` methods. Still the question stands how to detect the effectively executed test methods... which could be just a single method executed from your IDE – leo Sep 18 '19 at 11:23
  • What we try to do: Annotate each test method with an email to be sent to an integration environment. The emails of the **effectively executed methods** shall be sent in a batch before the Test starts, due to performance reasons, because the complex processing on the mail server will add latency of some tens of seconds. When executing just one test method, only its immediate Annotation shall be processed to send out an email. – leo Oct 21 '19 at 08:47

0 Answers0