Class GuiceRunner

  • All Implemented Interfaces:
    org.junit.runner.Describable, org.junit.runner.manipulation.Filterable, org.junit.runner.manipulation.Orderable, org.junit.runner.manipulation.Sortable

    public class GuiceRunner
    extends org.junit.runners.BlockJUnit4ClassRunner
    JUnit4 test runner that creates injector using the modules provided with GuiceModules configuration.

    Here is a simple test:

    
     @RunWith(GuiceRunner.class)
     @GuiceModules({MyModule.class})
     public class MyTest {
    
            @Inject
            Foo foo;
    
            public void testFooInjected() {
                    assertNotNull(foo);
            }
     }
    
     
    • Constructor Summary

      Constructors 
      Constructor Description
      GuiceRunner​(Class<?> klass)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Object createTest()  
      protected Injector getInjector()
      Get the Guice injector.
      protected List<Module> getModules​(Class<?> klass)  
      void run​(org.junit.runner.notification.RunNotifier notifier)  
      protected void validateZeroArgConstructor​(List<Throwable> errors)  
      • Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner

        collectInitializationErrors, computeTestMethods, createTest, describeChild, getChildren, getTestRules, isIgnored, methodBlock, methodInvoker, possiblyExpectingExceptions, rules, runChild, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, withAfters, withBefores, withPotentialTimeout
      • Methods inherited from class org.junit.runners.ParentRunner

        childrenInvoker, classBlock, classRules, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, order, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClasses, withInterruptIsolation
      • Methods inherited from class org.junit.runner.Runner

        testCount
    • Constructor Detail

      • GuiceRunner

        public GuiceRunner​(Class<?> klass)
                    throws org.junit.runners.model.InitializationError
        Throws:
        org.junit.runners.model.InitializationError
    • Method Detail

      • getModules

        protected List<Module> getModules​(Class<?> klass)
                                   throws org.junit.runners.model.InitializationError
        Throws:
        org.junit.runners.model.InitializationError
      • run

        public void run​(org.junit.runner.notification.RunNotifier notifier)
        Overrides:
        run in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
      • createTest

        public Object createTest()
        Overrides:
        createTest in class org.junit.runners.BlockJUnit4ClassRunner
      • getInjector

        protected Injector getInjector()
        Get the Guice injector.
        Returns:
        the injector
      • validateZeroArgConstructor

        protected void validateZeroArgConstructor​(List<Throwable> errors)
        Overrides:
        validateZeroArgConstructor in class org.junit.runners.BlockJUnit4ClassRunner