@Retention(value=RUNTIME) @Target(value=TYPE) @ExtendWith(value=TestGuiceyAppExtension.class) @Inherited public @interface TestGuiceyApp
Note: in spite of the fact that jersey not started, Managed objects would
be started and stopped normally.
Extension may be declared on test class or on any nested class. When declared on nested class, applies to all lower nested classes (default junit 5 extension appliance behaviour). Multiple extension declarations (on multiple nested levels) is useless as junit will use only the top declared extension instance (and other will be ignored).
Guice context started before all tests (before BeforeAll) and shut down
after all tests (after AfterAll). There is no way to restart it between tests. Group
test, not modifying internal application state and extract test modifying state to separate classes (possibly
junit nested tests).
Guice injections will work on test fields annotated with Inject or
Inject (Injector.injectMembers(Object) applied on test instance).
Guice AOP will not work on test methods (because test itself is not created by guice).
Test constructor, lifecycle and test methods may use additional parameters:
Jit to force JIT
binding (create declared bean with guice, even if it wasn't registered)Application or exact application classObjectMapperClientSupport for calling external urls
Internally use DropwizardTestSupport with custom command
(TestCommand).
It is possible to apply extension manually using RegisterExtension
and TestGuiceyAppExtension.forApp(Class) builder. The only difference is declaration type, but in both cases
extension will work the same way.
| Modifier and Type | Required Element and Description |
|---|---|
java.lang.Class<? extends io.dropwizard.Application> |
value |
| Modifier and Type | Optional Element and Description |
|---|---|
java.lang.String |
config |
java.lang.String[] |
configOverride
Each value must be written as
key: value. |
java.lang.Class<? extends GuiceyConfigurationHook>[] |
hooks
Hooks provide access to guice builder allowing complete customization of application context
in tests.
|
public abstract java.lang.Class<? extends io.dropwizard.Application> value
public abstract java.lang.String config
public abstract java.lang.String[] configOverride
key: value.public abstract java.lang.Class<? extends GuiceyConfigurationHook>[] hooks
For anonymous hooks you can simply declare hook as static field:
@EnableHook static GuiceyConfigurationHook hook = builder -> builder.disableExtension(Something.class)
All such fields will be detected automatically and hooks registered. Hooks declared in base test classes
are also counted.
for more info,
EnableHook