Interface TestExecutionListener
-
- All Known Implementing Classes:
AnnotatedTestFieldSetup,LogFieldsSupport,MockFieldsSupport,RestStubFieldsSupport,SpyFieldsSupport,StubFieldsSupport,TestExecutionListenerLambdaAdapter,TrackerFieldsSupport
public interface TestExecutionListenerTest 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
All Methods Instance Methods Default Methods Modifier and Type Method Description default voidafterAll(EventContext context)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 voidafterEach(EventContext context)Called after each test method execution.default voidbeforeAll(EventContext context)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 voidbeforeEach(EventContext context)Called before each test method execution.default voidstarted(EventContext context)Called when dropwizard (or guicey) application started.default voidstarting(EventContext context)Called before dropwizard (or guicey) application starting.default voidstopped(EventContext context)Called when dropwizard (or guicey) application stopped.default voidstopping(EventContext context)Called before dropwizard (or guicey) application stopping.
-
-
-
Method Detail
-
starting
default void starting(EventContext context) throws java.lang.Exception
Called before dropwizard (or guicey) application starting. It could be beforeAll or beforeEach phase (if important, lookExtensionContext.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:
java.lang.Exception- on error
-
started
default void started(EventContext context) throws java.lang.Exception
Called when dropwizard (or guicey) application started. It could be beforeAll or beforeEach phase (if important, lookExtensionContext.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:
java.lang.Exception- on error
-
beforeAll
default void beforeAll(EventContext context) throws java.lang.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). Preferstarted(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:
java.lang.Exception- on error
-
beforeEach
default void beforeEach(EventContext context) throws java.lang.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:
java.lang.Exception- on error
-
afterEach
default void afterEach(EventContext context) throws java.lang.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:
java.lang.Exception- on error
-
afterAll
default void afterAll(EventContext context) throws java.lang.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). Preferstopped(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:
java.lang.Exception- on error
-
stopping
default void stopping(EventContext context) throws java.lang.Exception
Called before dropwizard (or guicey) application stopping. It could be afterAll or afterEach phase (if important, lookExtensionContext.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:
java.lang.Exception- on error
-
stopped
default void stopped(EventContext context) throws java.lang.Exception
Called when dropwizard (or guicey) application stopped. It could be afterAll or afterEach phase (if important, lookExtensionContext.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:
java.lang.Exception- on error
-
-