Interface BeforeEachCallback

  • All Superinterfaces:
    Extension
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    @API(status=STABLE,
         since="5.0")
    public interface BeforeEachCallback
    extends Extension
    BeforeEachCallback defines the API for Extensions that wish to provide additional behavior to tests before each test is invoked.

    In this context, the term test refers to the actual test method plus any user defined setup methods (e.g., @BeforeEach methods).

    Concrete implementations often implement AfterEachCallback as well.

    Constructor Requirements

    Consult the documentation in Extension for details on constructor requirements.

    Wrapping Behavior

    JUnit Jupiter guarantees wrapping behavior for multiple registered extensions that implement lifecycle callbacks such as BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback, BeforeTestExecutionCallback, and AfterTestExecutionCallback.

    That means that, given two extensions Extension1 and Extension2 with Extension1 registered before Extension2, any "before" callbacks implemented by Extension1 are guaranteed to execute before any "before" callbacks implemented by Extension2. Similarly, given the two same two extensions registered in the same order, any "after" callbacks implemented by Extension1 are guaranteed to execute after any "after" callbacks implemented by Extension2. Extension1 is therefore said to wrap Extension2.

    Since:
    5.0
    See Also:
    BeforeEach, AfterEachCallback, BeforeTestExecutionCallback, AfterTestExecutionCallback, BeforeAllCallback, AfterAllCallback
    • Method Detail

      • beforeEach

        void beforeEach​(ExtensionContext context)
                 throws java.lang.Exception
        Callback that is invoked before each test is invoked.
        Parameters:
        context - the current extension context; never null
        Throws:
        java.lang.Exception