Interface TestExecutionListener

All Known Implementing Classes:
AnnotatedTestFieldSetup, LogFieldsSupport, MockFieldsSupport, RestStubFieldsSupport, SpyFieldsSupport, StubFieldsSupport, TestExecutionListenerLambdaAdapter, TrackerFieldsSupport, WebClientFieldsSupport, WebResourceClientFieldsSupport

public interface TestExecutionListener
Test listener allows listening for the main test events. There are no beforeAll and afterAll events directly because guicey extension could be created either on beforeAll or in beforeEach (depends on test configuration).

Before/after test called before and after each test method. This could be used for custom setup/cleanup logic. BeforeAll and afterAll might not be called - use with caution (depends on extension registration).

This interface provides a simple replacement for junit extension (synchronized with guicey lifecycle).

Since:
07.02.2025
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    IMPORTANT: this method MIGHT NOT BE CALLED at all in case if extension is registered under non-static field (and so the application is stopped after each method).
    default void
    Called after each test method execution.
    default void
    IMPORTANT: this method MIGHT NOT BE CALLED at all in case if extension is registered under non-static field (and so application created before each method).
    default void
    Called before each test method execution.
    default void
    Called when dropwizard (or guicey) application started.
    default void
    Called before dropwizard (or guicey) application starting.
    default void
    Called when dropwizard (or guicey) application stopped.
    default void
    Called before dropwizard (or guicey) application stopping.
  • Method Details

    • starting

      default void starting(EventContext context) throws Exception
      Called before dropwizard (or guicey) application starting. It could be beforeAll or beforeEach phase (if important, look ExtensionContext.getTestMethod() to make sure). Application could start/stop multiple times within one test class (if extension registered in non-static field).

      NOTE: At this stage, injections not yet performed inside test instance.

      This method could be used instead of beforeAll because normally extension is created under beforeAll, but for extensions created under beforeEach - it would be impossible to notify about beforeAll anyway.

      Parameters:
      context - context object providing access to all available objects (junit context, test support, etc.)
      Throws:
      Exception - on error
    • started

      default void started(EventContext context) throws Exception
      Called when dropwizard (or guicey) application started. It could be beforeAll or beforeEach phase (if important, look ExtensionContext.getTestMethod() to make sure). Application could start/stop multiple times within one test class (if extension registered in non-static field).

      NOTE: At this stage, injections not yet performed inside test instance.

      This method could be used instead of beforeAll because normally extension is created under beforeAll, but for extensions created under beforeEach - it would be impossible to notify about beforeAll anyway.

      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • beforeAll

      default void beforeAll(EventContext context) throws Exception
      IMPORTANT: this method MIGHT NOT BE CALLED at all in case if extension is registered under non-static field (and so application created before each method). Prefer started(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext) instead, which is always called (but not always under beforeAll),

      Method could be useful if some action must be performed before each test (in case of nested tests or global application when "start" would not be called for each test).

      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • beforeEach

      default void beforeEach(EventContext context) throws Exception
      Called before each test method execution. Guice injections into test instance already performed. Even if an application is created in beforeEach phase, this method would be called after application creation.
      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • afterEach

      default void afterEach(EventContext context) throws Exception
      Called after each test method execution. Even if an application is closed on afterEach, this method would be called before it.
      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • afterAll

      default void afterAll(EventContext context) throws Exception
      IMPORTANT: this method MIGHT NOT BE CALLED at all in case if extension is registered under non-static field (and so the application is stopped after each method). Prefer stopped(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext) instead, which is always called (but not always under afterAll),

      Method could be useful if some action must be performed after each test (in case of nested tests or global application when "stop" would not be called for each test).

      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • stopping

      default void stopping(EventContext context) throws Exception
      Called before dropwizard (or guicey) application stopping. It could be afterAll or afterEach phase (if important, look ExtensionContext.getTestMethod() to make sure). Application could start/stop multiple times within one test class (if extension registered in non-static field).

      Note that in case of global application usage or for nested tests this method might not be called because application lifecycle would be managed by the top-most test.

      This method could be used instead of afterAll because normally extension is stopped under afterAll, but for extensions stopped under afterEach - it would be impossible to notify about afterAll anyway.

      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • stopped

      default void stopped(EventContext context) throws Exception
      Called when dropwizard (or guicey) application stopped. It could be afterAll or afterEach phase (if important, look ExtensionContext.getTestMethod() to make sure). Application could start/stop multiple times within one test class (if extension registered in non-static field).

      Note that in case of global application usage or for nested tests this method might not be called because application lifecycle would be managed by the top-most test.

      This method could be used instead of afterAll because normally extension is stopped under afterAll, but for extensions stopped under afterEach - it would be impossible to notify about afterAll anyway.

      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error