Skip to content

Latest commit

 

History

History
40 lines (36 loc) · 833 Bytes

README.md

File metadata and controls

40 lines (36 loc) · 833 Bytes

Guice JUnit

Provide a simple and basic JUnit 5 extension to inject Guice members into JUnit 5 tests.

Installation

With Maven:

<dependency>
  <groupId>com.coreoz</groupId>
  <artifactId>guice-junit</artifactId>
  <version>1.0.0</version>
</dependency>

Getting started

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();
    }
}