Class 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 SandboxTestRunner
    Loads and runs a test in a SandboxClassLoader in order to provide a simulation of the Android runtime environment.
    • Constructor Detail

      • 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,
                                        Injector injector)
                                 throws org.junit.runners.model.InitializationError
        Throws:
        org.junit.runners.model.InitializationError
    • Method Detail

      • createClassHandler

        @Nonnull
        protected ClassHandler createClassHandler​(ShadowMap shadowMap,
                                                  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 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
      • 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
      • afterTest

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

        protected ManifestFactory getManifestFactory​(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()
      • getConfig

        @Deprecated
        public Config getConfig​(Method method)
        Deprecated.
        Provide an implementation of Provider 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:
        Migration Notes for more details.
      • buildGlobalConfig

        @Deprecated
        protected 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:
        Migration Notes for more details.
      • createTest

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