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
SandboxClassLoader in order to provide a simulation of the
 Android runtime environment.- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classRobolectricTestRunner.DeprecatedTestRunnerDefaultConfigProviderDeprecated.static classRobolectricTestRunner.HelperTestRunnerstatic classRobolectricTestRunner.RobolectricFrameworkMethodFields in this class must be serializable using XStream.
- 
Field SummaryFields Modifier and Type Field Description static StringCONFIG_PROPERTIES
- 
Constructor SummaryConstructors Modifier Constructor Description RobolectricTestRunner(Class<?> testClass)Creates a runner to runtestClass.protectedRobolectricTestRunner(Class<?> testClass, Injector injector)
- 
Method SummaryModifier and Type Method Description protected voidafterClass()protected voidafterTest(org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod)protected voidbeforeTest(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod)protected ConfigbuildGlobalConfig()Deprecated.Provide a service implementation ofGlobalConfigProviderinstead.static AndroidManifestcreateAndroidManifest(ManifestIdentifier manifestIdentifier)Deprecated.Do not use.protected ClassHandlercreateClassHandler(ShadowMap shadowMap, Sandbox sandbox)Create aClassHandlerappropriate for the given arguments.protected InstrumentationConfigurationcreateClassLoaderConfig(org.junit.runners.model.FrameworkMethod method)Create anInstrumentationConfigurationsuitable for the providedFrameworkMethod.ObjectcreateTest()protected static Injector.BuilderdefaultInjector()protected voidfinallyAfterTest(org.junit.runners.model.FrameworkMethod method)protected Collection<Interceptor>findInterceptors()protected PropertiesgetBuildSystemApiProperties()protected List<org.junit.runners.model.FrameworkMethod>getChildren()ConfiggetConfig(Method method)Deprecated.Provide an implementation ofProviderinstead.protected Class<?>[]getExtraShadows(org.junit.runners.model.FrameworkMethod frameworkMethod)protected SandboxTestRunner.HelperTestRunnergetHelperTestRunner(Class<?> bootstrappedTestClass)protected ManifestFactorygetManifestFactory(Config config)Detects which build system is in use and returns the appropriate ManifestFactory implementation.protected AndroidSandboxgetSandbox(org.junit.runners.model.FrameworkMethod method)protected Class<? extends TestLifecycle>getTestLifecycleClass()An instance of the returned class will be created for each test invocation.protected static PropertiesstaticGetBuildSystemApiProperties()Methods inherited from class org.robolectric.internal.SandboxTestRunnerclassBlock, configureSandbox, getInterceptors, methodBlock, withPotentialTimeoutMethods inherited from class org.junit.runners.BlockJUnit4ClassRunnercollectInitializationErrors, computeTestMethods, createTest, describeChild, getTestRules, isIgnored, methodInvoker, possiblyExpectingExceptions, rules, runChild, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withBeforesMethods inherited from class org.junit.runners.ParentRunnerchildrenInvoker, classRules, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, order, run, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClasses, withInterruptIsolation
- 
Field Details- 
CONFIG_PROPERTIES- See Also:
- Constant Field Values
 
 
- 
- 
Constructor Details- 
RobolectricTestRunnerpublic RobolectricTestRunner(Class<?> testClass) throws org.junit.runners.model.InitializationErrorCreates a runner to runtestClass. Use theConfigannotation to configure.- Parameters:
- testClass- the test class to be run
- Throws:
- org.junit.runners.model.InitializationError- if junit says so
 
- 
RobolectricTestRunnerprotected RobolectricTestRunner(Class<?> testClass, Injector injector) throws org.junit.runners.model.InitializationError- Throws:
- org.junit.runners.model.InitializationError
 
 
- 
- 
Method Details- 
defaultInjector
- 
createClassHandlerCreate aClassHandlerappropriate for the given arguments.Robolectric may chose to cache the returned instance, keyed by shadowMapandsandbox.Custom TestRunner subclasses may wish to override this method to provide alternate configuration. - Overrides:
- createClassHandlerin class- SandboxTestRunner
- Parameters:
- shadowMap- the- ShadowMapin effect for this test
- sandbox- the- Sdkin effect for this test
- Returns:
- an appropriate ShadowWrangler.
- Since:
- 2.3
 
- 
findInterceptors- Overrides:
- findInterceptorsin class- SandboxTestRunner
 
- 
createClassLoaderConfig@Nonnull protected InstrumentationConfiguration createClassLoaderConfig(org.junit.runners.model.FrameworkMethod method)Create anInstrumentationConfigurationsuitable for the providedFrameworkMethod.Adds configuration for Android using AndroidConfigurer.Custom TestRunner subclasses may wish to override this method to provide additional configuration. - Overrides:
- createClassLoaderConfigin class- SandboxTestRunner
- Parameters:
- method- the test method that's about to run
- Returns:
- an InstrumentationConfiguration
 
- 
getTestLifecycleClassAn 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 aDefaultTestLifecycle.
 
- 
getChildren- Overrides:
- getChildrenin class- org.junit.runners.BlockJUnit4ClassRunner
 
- 
getSandbox- Overrides:
- getSandboxin class- SandboxTestRunner
 
- 
beforeTestprotected void beforeTest(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod) throws Throwable- Overrides:
- beforeTestin class- SandboxTestRunner
- Throws:
- Throwable
 
- 
afterTestprotected void afterTest(org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod)- Overrides:
- afterTestin class- SandboxTestRunner
 
- 
finallyAfterTestprotected void finallyAfterTest(org.junit.runners.model.FrameworkMethod method)- Overrides:
- finallyAfterTestin class- SandboxTestRunner
 
- 
getHelperTestRunnerprotected SandboxTestRunner.HelperTestRunner getHelperTestRunner(Class<?> bootstrappedTestClass) throws org.junit.runners.model.InitializationError- Overrides:
- getHelperTestRunnerin class- SandboxTestRunner
- Throws:
- org.junit.runners.model.InitializationError
 
- 
getManifestFactoryDetects 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
- 
staticGetBuildSystemApiProperties
- 
createAndroidManifest@Deprecated public static AndroidManifest createAndroidManifest(ManifestIdentifier manifestIdentifier)Deprecated.Do not use.Internal use only.
- 
getConfigDeprecated.Provide an implementation ofProviderinstead. 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.propertiesfiles andConfigannotations 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.
 
- 
buildGlobalConfigDeprecated.Provide a service implementation ofGlobalConfigProviderinstead. This method will be removed in Robolectric 4.3.Provides the base Robolectric configurationConfigused 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 Configobject
- Since:
- 3.1.3
- See Also:
- Migration Notes for more details.
 
- 
getExtraShadows@Nonnull protected Class<?>[] getExtraShadows(org.junit.runners.model.FrameworkMethod frameworkMethod)- Overrides:
- getExtraShadowsin class- SandboxTestRunner
 
- 
afterClassprotected void afterClass()- Overrides:
- afterClassin class- SandboxTestRunner
 
- 
createTest- Overrides:
- createTestin class- org.junit.runners.BlockJUnit4ClassRunner
- Throws:
- Exception
 
 
-