A Guice JUnit Runner
guice-junit-runner is a JUnit Runner allowing Guice-based testing. Each test method is running with a clean Injector instance.
@RunWith(GuiceJUnitRunner.class)
public class GuiceJUnitRunnerTest {
@Inject
public MyService service;
@Test
public void test() {
// ...
}
}
You can easily add one more modules by using the @GuiceModules annotation.
@RunWith(GuiceJUnitRunner.class)
@GuiceModules(TestModule.class)
public class GuiceJUnitRunnerTest {
public static class TestModule extends AbstractModule {
@Override
protected void configure() {
bind(MyService.class).to(MyServiceImpl.class);
// ...
}
}
@Inject
public MyService service;
@Test
@GuiceModules(TestModule2.class)
public void perTestSpecificModule() {
// ...
}
@Test
public void test() {
// ...
}
}