Annotation Type BeforeParameterizedClassInvocation


  • @Target({ANNOTATION_TYPE,METHOD})
    @Retention(RUNTIME)
    @Documented
    @API(status=MAINTAINED,
         since="5.13.3")
    public @interface BeforeParameterizedClassInvocation
    @BeforeParameterizedClassInvocation is used to signal that the annotated method should be executed before each invocation of the current @ParameterizedClass.

    Declaring @BeforeParameterizedClassInvocation methods in a regular, non-parameterized test class has no effect and will be ignored.

    Method Signatures

    @BeforeParameterizedClassInvocation methods must have a void return type, must not be private, and must be static by default. Consequently, @BeforeParameterizedClassInvocation methods are not supported in @Nested test classes or as interface default methods unless the test class is annotated with @TestInstance(Lifecycle.PER_CLASS). However, beginning with Java 16 @BeforeParameterizedClassInvocation methods may be declared as static in @Nested test classes, in which case the Lifecycle.PER_CLASS restriction no longer applies.

    Method Arguments

    @BeforeParameterizedClassInvocation methods may optionally declare parameters that are resolved depending on the setting of the injectArguments() attribute.

    If injectArguments() is set to false, the parameters must be resolved by other registered ParameterResolvers.

    If injectArguments() is set to true (the default), the method must declare the same parameters, in the same order, as the indexed parameters (see @ParameterizedClass) of the parameterized test class. It may declare a subset of the indexed parameters starting from the first argument. Additionally, the method may declare custom aggregator parameters (see @ParameterizedClass) at the end of its parameter list. If the method declares additional parameters after these aggregator parameters, or more parameters than the class has indexed parameters, they may be resolved by other ParameterResolvers.

    For example, given a @ParameterizedClass with indexed parameters of type int and String, the following method signatures are valid:

    {@code
    Since:
    5.13
    See Also:
    ParameterizedClass, AfterParameterizedClassInvocation, TestInstance
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean injectArguments
      Whether the arguments of the parameterized test class should be injected into the annotated method (defaults to true).
    • Element Detail

      • injectArguments

        boolean injectArguments
        Whether the arguments of the parameterized test class should be injected into the annotated method (defaults to true).
        Default:
        true