Package io.quarkus.test.common
Interface QuarkusTestResourceLifecycleManager
-
- All Known Subinterfaces:
QuarkusTestResourceConfigurableLifecycleManager<ConfigAnnotation>
public interface QuarkusTestResourceLifecycleManager
Manage the lifecycle of a test resource, for instance a H2 test server.These resources are started before the first test is run, and are closed at the end of the test suite. They are configured via the
QuarkusTestResource
annotation, which can be placed on any class in the test suite. These can also be loaded via a service loader mechanism, however if a service loader is used it should not also be annotated as this will result in it being executed twice. Note that when using these with QuarkusUnitTest (rather than @QuarkusTest) they run before the ClassLoader has been setup. This means injection may not work as expected.Due to the very early execution in the test setup lifecycle, logging does not work in such a manager.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
QuarkusTestResourceLifecycleManager.Context
static interface
QuarkusTestResourceLifecycleManager.TestInjector
Provides methods to handle the common injection cases.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
init(Map<String,String> initArgs)
Arguments passed to the lifecycle manager before it starts These arguments are taken fromQuarkusTestResource#initArgs()
Theargs
is never nulldefault void
inject(QuarkusTestResourceLifecycleManager.TestInjector testInjector)
Simplifies the injection of fields of the test class by providing methods to handle the common injection cases.default void
inject(Object testInstance)
Allow each resource to provide custom injection of fields of the test class.default int
order()
If multiple Test Resources are specified, this control the order of which they will be executed.default void
setContext(QuarkusTestResourceLifecycleManager.Context context)
Set the context in which thisQuarkusTestResourceLifecycleManager
is being used.Map<String,String>
start()
Start the test resource.void
stop()
Stop the test resource.
-
-
-
Method Detail
-
start
Map<String,String> start()
Start the test resource.- Returns:
- A map of configuration properties that will be set for the running test
-
stop
void stop()
Stop the test resource.
-
setContext
default void setContext(QuarkusTestResourceLifecycleManager.Context context)
Set the context in which thisQuarkusTestResourceLifecycleManager
is being used. This method is executed before theinit
method. Thecontext
is never null.
-
init
default void init(Map<String,String> initArgs)
Arguments passed to the lifecycle manager before it starts These arguments are taken fromQuarkusTestResource#initArgs()
Theargs
is never null- See Also:
QuarkusTestResource.initArgs()
-
inject
default void inject(Object testInstance)
Allow each resource to provide custom injection of fields of the test class. Most implementations will likely useinject(TestInjector)
as it provides a simpler way to inject into fields of tests. It is worth mentioning that this injection into the test class is not under the control of CDI and happens after CDI has performed any necessary injections into the test class.
-
inject
default void inject(QuarkusTestResourceLifecycleManager.TestInjector testInjector)
Simplifies the injection of fields of the test class by providing methods to handle the common injection cases. In situations not covered byQuarkusTestResourceLifecycleManager.TestInjector
, user can resort to implementinginject(Object)
It is worth mentioning that this injection into the test class is not under the control of CDI and happens after CDI has performed any necessary injections into the test class.
-
order
default int order()
If multiple Test Resources are specified, this control the order of which they will be executed.- Returns:
- The order to be executed. The larger the number, the later the Resource is invoked.
-
-