Annotation Type TestGuiceyApp
-
@Retention(RUNTIME) @Target(TYPE) @ExtendWith(TestGuiceyAppExtension.class) @Inherited public @interface TestGuiceyApp
Guicey app junit 5 extension. Runs only guice context without starting web part (jetty and jersey). Useful for testing core business services.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 (afterAfterAll
). 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
orInject
(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:
- Any declared (possibly with qualifier annotation or generified) guice bean
- For not declared beans use
Jit
to force JIT binding (create declared bean with guice, even if it wasn't registered) - Specially supported objects:
Application
or exact application classObjectMapper
ClientSupport
for calling external urls
Internally use
DropwizardTestSupport
with custom command (TestCommand
).It is possible to apply extension manually using
RegisterExtension
andTestGuiceyAppExtension.forApp(Class)
builder. The only difference is declaration type, but in both cases extension will work the same way.- Since:
- 29.04.2020
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description java.lang.Class<? extends io.dropwizard.Application>
value
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.String
config
java.lang.String[]
configOverride
Each value must be written askey: value
.java.lang.Class<? extends GuiceyConfigurationHook>[]
hooks
Hooks provide access to guice builder allowing complete customization of application context in tests.
-
-
-
-
configOverride
java.lang.String[] configOverride
Each value must be written askey: value
.In order to specify raw
ConfigOverride
values (for delayed evaluation) use direct extension registration withRegisterExtension
instead of annotation.- Returns:
- list of overridden configuration values (may be used even without real configuration)
- Default:
- {}
-
-
-
hooks
java.lang.Class<? extends GuiceyConfigurationHook>[] hooks
Hooks provide access to guice builder allowing complete customization of application context in tests.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.- Returns:
- list of hooks to use
- See Also:
for more info
,EnableHook
- Default:
- {}
-
-