Annotation Type TestGuiceyApp
@Retention(RUNTIME) @Target(TYPE) @ExtendWith(TestGuiceyAppExtension.class) @Inherited public @interface TestGuiceyAppGuicey 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,
Managedobjects 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
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
Jitto force JIT binding (create declared bean with guice, even if it wasn't registered)
- Specially supported objects:
Applicationor exact application class
ClientSupportfor calling external urls
DropwizardTestSupportwith custom command (
It is possible to apply extension manually using
TestGuiceyAppExtension.forApp(Class)builder. The only difference is declaration type, but in both cases extension will work the same way.
Required Element Summary
Required Elements Modifier and Type Required Element Description
java.lang.Class<? extends io.dropwizard.Application>
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description
configOverrideEach value must be written as
java.lang.Class<? extends GuiceyConfigurationHook>
hooksHooks provide access to guice builder allowing complete customization of application context in tests.
java.lang.String configOverrideEach value must be written as
In order to specify raw
ConfigOverridevalues (for delayed evaluation) use direct extension registration with
RegisterExtensioninstead of annotation.
- list of overridden configuration values (may be used even without real configuration)
java.lang.Class<? extends GuiceyConfigurationHook> hooksHooks 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.