public class GuiceyHooksRule
extends org.junit.rules.ExternalResource
DropwizardAppRule or
GuiceyAppRule. Must be used ONLY with RuleChain because normally rules order
is not predictable:
static GuiceyAppRule RULE = new GuiceyAppRule(App.class, null);
{@literal @}ClassRule
public static RuleChain chain = RuleChain
.outerRule(new GuiceyHooksRule((builder) -> builder.modules(...)))
.around(RULE);
To declare common extensions for all tests, declare common rule in test class (without @ClassRule
annotation!) and use it in chain:
public class BaseTest {
static GuiceyHooksRule BASE = new GuiceyHooksRule((builder) -> builder.modules(...))
}
public class SomeTest extends BaseTest {
static GuiceyAppRule RULE = new GuiceyAppRule(App.class, null);
{@literal @}ClassRule
public static RuleChain chain = RuleChain
.outerRule(BASE)
.around(new GuiceyHooksRule((builder) -> builder.modules(...)) // optional test-specific staff
.around(RULE);
}
IMPORTANT: rule will not work with spock extensions (because of lifecycle specifics)! Use
UseGuiceyHooks or new hooks attribute in
UseGuiceyApp or
UseDropwizardApp instead.
Rule is thread safe: it is assumed that rule will be applied at the same thread as test application initialization.
| Constructor and Description |
|---|
GuiceyHooksRule(GuiceyConfigurationHook... hooks) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
after() |
protected void |
before() |
public GuiceyHooksRule(GuiceyConfigurationHook... hooks)