Provide a simple and basic JUnit 5 extension to inject Guice members into JUnit 5 tests.
With Maven:
<dependency>
<groupId>com.coreoz</groupId>
<artifactId>guice-junit</artifactId>
<version>1.0.0</version>
</dependency>
Declare a Guice module dedicated for tests, or use an existing module:
public class SampleModule extends AbstractModule {
@Override
protected void configure() {
bind(Clock.class).toInstance(Clock.systemDefaultZone());
}
}
Make a JUnit test inject module members:
@GuiceTest(SampleModule.class)
class SampleTest {
@Inject
Clock clock;
@Test
public void verify_that_clock_object_is_injected() {
Assertions.assertThat(clock).isNotNull();
}
}