Class RobolectricTestRunner

java.lang.Object
org.junit.runner.Runner
org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
org.junit.runners.BlockJUnit4ClassRunner
org.robolectric.internal.SandboxTestRunner
org.robolectric.RobolectricTestRunner
All Implemented Interfaces:
org.junit.runner.Describable, org.junit.runner.manipulation.Filterable, org.junit.runner.manipulation.Orderable, org.junit.runner.manipulation.Sortable

public class RobolectricTestRunner extends org.robolectric.internal.SandboxTestRunner
Loads and runs a test in a SandboxClassLoader in order to provide a simulation of the Android runtime environment.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Deprecated.
    static class 
     
    static class 
    A FrameworkMethod subclass that contains data required to run Robolectric tests.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     

    Fields inherited from class org.robolectric.internal.SandboxTestRunner

    classHandlerBuilder
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Creates a runner to run testClass.
    protected
    RobolectricTestRunner(Class<?> testClass, org.robolectric.util.inject.Injector injector)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    protected void
    afterTest(org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod)
     
    protected void
    beforeTest(org.robolectric.internal.bytecode.Sandbox sandbox, org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod)
     
    protected org.robolectric.annotation.Config
    Deprecated.
    Provide a service implementation of GlobalConfigProvider instead.
    static org.robolectric.manifest.AndroidManifest
    Deprecated.
    Do not use.
    protected org.robolectric.internal.bytecode.ClassHandler
    createClassHandler(org.robolectric.internal.bytecode.ShadowMap shadowMap, org.robolectric.internal.bytecode.Sandbox sandbox)
    Create a ClassHandler appropriate for the given arguments.
    protected org.robolectric.internal.bytecode.InstrumentationConfiguration
    createClassLoaderConfig(org.junit.runners.model.FrameworkMethod method)
    Create an InstrumentationConfiguration suitable for the provided FrameworkMethod.
     
    protected static org.robolectric.util.inject.Injector.Builder
     
    protected void
    finallyAfterTest(org.junit.runners.model.FrameworkMethod method)
     
    protected Collection<org.robolectric.internal.bytecode.Interceptor>
     
    protected Properties
     
    protected List<org.junit.runners.model.FrameworkMethod>
     
    org.robolectric.annotation.Config
    getConfig(Method method)
    Deprecated.
    Provide an implementation of javax.inject.Provider<org.robolectric.annotation.Config> instead.
    protected Class<?>[]
    getExtraShadows(org.junit.runners.model.FrameworkMethod frameworkMethod)
     
    protected org.robolectric.internal.SandboxTestRunner.HelperTestRunner
    getHelperTestRunner(Class<?> bootstrappedTestClass)
     
    protected ManifestFactory
    getManifestFactory(org.robolectric.annotation.Config config)
    Detects which build system is in use and returns the appropriate ManifestFactory implementation.
    protected AndroidSandbox
    getSandbox(org.junit.runners.model.FrameworkMethod method)
     
    protected Class<? extends TestLifecycle>
    An instance of the returned class will be created for each test invocation.
    protected static Properties
     

    Methods inherited from class org.robolectric.internal.SandboxTestRunner

    classBlock, configureSandbox, getInterceptors, methodBlock, withPotentialTimeout

    Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner

    collectInitializationErrors, computeTestMethods, createTest, describeChild, getTestRules, isIgnored, methodInvoker, possiblyExpectingExceptions, rules, runChild, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withBefores

    Methods inherited from class org.junit.runners.ParentRunner

    childrenInvoker, classRules, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, order, run, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClasses, withInterruptIsolation

    Methods inherited from class org.junit.runner.Runner

    testCount

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • RobolectricTestRunner

      public RobolectricTestRunner(Class<?> testClass) throws org.junit.runners.model.InitializationError
      Creates a runner to run testClass. Use the Config annotation to configure.
      Parameters:
      testClass - the test class to be run
      Throws:
      org.junit.runners.model.InitializationError - if junit says so
    • RobolectricTestRunner

      protected RobolectricTestRunner(Class<?> testClass, org.robolectric.util.inject.Injector injector) throws org.junit.runners.model.InitializationError
      Throws:
      org.junit.runners.model.InitializationError
  • Method Details

    • defaultInjector

      protected static org.robolectric.util.inject.Injector.Builder defaultInjector()
    • createClassHandler

      @Nonnull protected org.robolectric.internal.bytecode.ClassHandler createClassHandler(org.robolectric.internal.bytecode.ShadowMap shadowMap, org.robolectric.internal.bytecode.Sandbox sandbox)
      Create a ClassHandler appropriate for the given arguments.

      Robolectric may chose to cache the returned instance, keyed by shadowMap and sandbox.

      Custom TestRunner subclasses may wish to override this method to provide alternate configuration.

      Overrides:
      createClassHandler in class org.robolectric.internal.SandboxTestRunner
      Parameters:
      shadowMap - the ShadowMap in effect for this test
      sandbox - the Sdk in effect for this test
      Returns:
      an appropriate ShadowWrangler.
      Since:
      2.3
    • findInterceptors

      @Nonnull protected Collection<org.robolectric.internal.bytecode.Interceptor> findInterceptors()
      Overrides:
      findInterceptors in class org.robolectric.internal.SandboxTestRunner
    • createClassLoaderConfig

      @Nonnull protected org.robolectric.internal.bytecode.InstrumentationConfiguration createClassLoaderConfig(org.junit.runners.model.FrameworkMethod method)
      Create an InstrumentationConfiguration suitable for the provided FrameworkMethod.

      Adds configuration for Android using AndroidConfigurer.

      Custom TestRunner subclasses may wish to override this method to provide additional configuration.

      Overrides:
      createClassLoaderConfig in class org.robolectric.internal.SandboxTestRunner
      Parameters:
      method - the test method that's about to run
      Returns:
      an InstrumentationConfiguration
    • getTestLifecycleClass

      @Nonnull protected Class<? extends TestLifecycle> getTestLifecycleClass()
      An instance of the returned class will be created for each test invocation.

      Custom TestRunner subclasses may wish to override this method to provide alternate configuration.

      Returns:
      a class which implements TestLifecycle. This implementation returns a DefaultTestLifecycle.
    • getChildren

      protected List<org.junit.runners.model.FrameworkMethod> getChildren()
      Overrides:
      getChildren in class org.junit.runners.BlockJUnit4ClassRunner
    • getSandbox

      @Nonnull protected AndroidSandbox getSandbox(org.junit.runners.model.FrameworkMethod method)
      Overrides:
      getSandbox in class org.robolectric.internal.SandboxTestRunner
    • beforeTest

      protected void beforeTest(org.robolectric.internal.bytecode.Sandbox sandbox, org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod) throws Throwable
      Overrides:
      beforeTest in class org.robolectric.internal.SandboxTestRunner
      Throws:
      Throwable
    • afterTest

      protected void afterTest(org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod)
      Overrides:
      afterTest in class org.robolectric.internal.SandboxTestRunner
    • finallyAfterTest

      protected void finallyAfterTest(org.junit.runners.model.FrameworkMethod method)
      Overrides:
      finallyAfterTest in class org.robolectric.internal.SandboxTestRunner
    • getHelperTestRunner

      protected org.robolectric.internal.SandboxTestRunner.HelperTestRunner getHelperTestRunner(Class<?> bootstrappedTestClass) throws org.junit.runners.model.InitializationError
      Overrides:
      getHelperTestRunner in class org.robolectric.internal.SandboxTestRunner
      Throws:
      org.junit.runners.model.InitializationError
    • getManifestFactory

      protected ManifestFactory getManifestFactory(org.robolectric.annotation.Config config)
      Detects which build system is in use and returns the appropriate ManifestFactory implementation.

      Custom TestRunner subclasses may wish to override this method to provide alternate configuration.

      Parameters:
      config - Specification of the SDK version, manifest file, package name, etc.
    • getBuildSystemApiProperties

      protected Properties getBuildSystemApiProperties()
    • staticGetBuildSystemApiProperties

      protected static Properties staticGetBuildSystemApiProperties()
    • createAndroidManifest

      @Deprecated public static org.robolectric.manifest.AndroidManifest createAndroidManifest(ManifestIdentifier manifestIdentifier)
      Deprecated.
      Do not use.
      Internal use only.
    • getConfig

      @Deprecated public org.robolectric.annotation.Config getConfig(Method method)
      Deprecated.
      Provide an implementation of javax.inject.Provider<org.robolectric.annotation.Config> instead. This method will be removed in Robolectric 4.3.
      Compute the effective Robolectric configuration for a given test method.

      Configuration information is collected from package-level robolectric.properties files and Config annotations on test classes, superclasses, and methods.

      Custom TestRunner subclasses may wish to override this method to provide alternate configuration.

      Parameters:
      method - the test method
      Returns:
      the effective Robolectric configuration for the given test method
      Since:
      2.0
      See Also:
    • buildGlobalConfig

      @Deprecated protected org.robolectric.annotation.Config buildGlobalConfig()
      Deprecated.
      Provide a service implementation of GlobalConfigProvider instead. This method will be removed in Robolectric 4.3.
      Provides the base Robolectric configuration Config used for all tests.

      Configuration provided for specific packages, test classes, and test method configurations will override values provided here.

      Custom TestRunner subclasses may wish to override this method to provide alternate configuration. Consider using a Config.Builder.

      The default implementation has appropriate values for most use cases.

      Returns:
      global Config object
      Since:
      3.1.3
      See Also:
    • getExtraShadows

      @Nonnull protected Class<?>[] getExtraShadows(org.junit.runners.model.FrameworkMethod frameworkMethod)
      Overrides:
      getExtraShadows in class org.robolectric.internal.SandboxTestRunner
    • afterClass

      protected void afterClass()
      Overrides:
      afterClass in class org.robolectric.internal.SandboxTestRunner
    • createTest

      public Object createTest() throws Exception
      Overrides:
      createTest in class org.junit.runners.BlockJUnit4ClassRunner
      Throws:
      Exception