Interface LifecycleContext

All Known Subinterfaces:
ContainerLifecycleContext, MethodLifecycleContext, PropertyLifecycleContext, TryLifecycleContext

@API(status=MAINTAINED, since="1.4.0") public interface LifecycleContext
Supertype of all lifecycle context interfaces.
See Also:
  • Method Details

    • label

      String label()
      The elements label under which it shows up in test reports and IDEs.
      Returns:
      a String
    • optionalElement

      Optional<AnnotatedElement> optionalElement()
      If the context refers to a class or a method the class or method is returned, otherwise Optional.empty()
      Returns:
      an optional annotated element
    • optionalContainerClass

      Optional<Class<?>> optionalContainerClass()
      If the context refers to a class or a method the class or the method's class is returned, otherwise Optional.empty()
      Returns:
      an optional annotated element
    • reporter

      Reporter reporter()
      Get hold of test reporter for publishing additional information on a test container or method.
      Returns:
      Current instance to test reporter
    • wrapReporter

      @API(status=EXPERIMENTAL, since="1.5.1") void wrapReporter(Function<Reporter,Reporter> wrapper)
      Wrap reporter instance
      Parameters:
      wrapper - Wrapping function that takes original reporter and returns a wrapped instance
    • findAnnotation

      <T extends Annotation> Optional<T> findAnnotation(Class<T> annotationClass)
      Retrieve an annotation if present at the current test element.
      Type Parameters:
      T - The annotation type
      Parameters:
      annotationClass - The annotation type
      Returns:
      instance of annotation type
    • findAnnotationsInContainer

      <T extends Annotation> List<T> findAnnotationsInContainer(Class<T> annotationClass)
      Retrieve an annotation if present in the current element's containers. Search up the container stack. Closest container annotations come first in list.
      Type Parameters:
      T - The annotation type
      Parameters:
      annotationClass - The annotation type
      Returns:
      list of annotation objects
    • findRepeatableAnnotations

      @API(status=MAINTAINED, since="1.7.4") <T extends Annotation> List<T> findRepeatableAnnotations(Class<T> annotationClass)
      Retrieve a list of repeatable annotations if present at the current test element.
      Type Parameters:
      T - The annotation type
      Parameters:
      annotationClass - The annotation type
      Returns:
      list of annotation objects
    • newInstance

      <T> T newInstance(Class<T> clazz)
      Create a new instance of a clazz in the context of the property in which it is running. Use this method, for example, when trying to instantiate a class retrieved from an annotation's attribute.

      The behaviour of this method differs from Class.newInstance() if the class to instantiate is a non-static member of the container class or even a nested container class.

      Type Parameters:
      T - The type to instantiate
      Parameters:
      clazz - The class to instantiate
      Returns:
      a freshly created instance of class clazz
    • resolveParameter

      Optional<ResolveParameterHook.ParameterSupplier> resolveParameter(Executable executable, int index)
      Resolve a parameter from a method in the context of the property in which it is running.
      Parameters:
      executable - The executable of the test container the parameter of which should be resolved
      index - The parameter's position in a method - starting with 0.
      Returns:
      supplier instance
      Throws:
      CannotResolveParameterException - if parameter cannot be resolved