public class NeedleTestRule extends NeedleTestcase implements org.junit.rules.TestRule
TestRule for the initialization of the test. The Rule processes
and initializes all fields annotated with ObjectUnderTest.
This is an updated Rule to reflect the API change (MethodRule vs. TestRule)
in junit. Using this TestRule implementation has the drawback that the
calling test-instance has to be passed when the Rule is created, since the
new junit api does not pass the caller to the statement execution.RuleChains feature of junit >= 4.10.
Example:
public class UserDaoBeanTest {
@Rule
public final NeedleTestRule needle = new NeedleTestRule(this);
@ObjectUnderTest
private UserDaoBean userDao;
@Test
public void test() {
...
userDao.someAction();
...
}
}
NeedleRule,
NeedleTestcase| Constructor and Description |
|---|
NeedleTestRule(Object testInstance,
InjectionProvider<?>... injectionProviders) |
| Modifier and Type | Method and Description |
|---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
getInjectedObject, getMockProviderpublic NeedleTestRule(Object testInstance, InjectionProvider<?>... injectionProviders)
testInstance - - target of injectioninjectionProviders - - optional custom injection providerNeedleTestcase.NeedleTestcase(InjectionProvider...)Copyright © 2014. All rights reserved.