Class RobolectricTestRunner
- All Implemented Interfaces:
org.junit.runner.Describable
,org.junit.runner.manipulation.Filterable
,org.junit.runner.manipulation.Orderable
,org.junit.runner.manipulation.Sortable
SandboxClassLoader
in order to provide a simulation of the
Android runtime environment.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Deprecated.static class
static class
AFrameworkMethod
subclass that contains data required to run Robolectric tests. -
Field Summary
Fields inherited from class org.robolectric.internal.SandboxTestRunner
classHandlerBuilder
-
Constructor Summary
ModifierConstructorDescriptionRobolectricTestRunner
(Class<?> testClass) Creates a runner to runtestClass
.protected
RobolectricTestRunner
(Class<?> testClass, Injector injector) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected void
protected void
beforeTest
(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod) protected Config
Deprecated.static AndroidManifest
createAndroidManifest
(ManifestIdentifier manifestIdentifier) Deprecated.Do not use.protected ClassHandler
createClassHandler
(ShadowMap shadowMap, Sandbox sandbox) Create aClassHandler
appropriate for the given arguments.protected InstrumentationConfiguration
createClassLoaderConfig
(org.junit.runners.model.FrameworkMethod method) Create anInstrumentationConfiguration
suitable for the providedFrameworkMethod
.protected static Injector.Builder
protected void
finallyAfterTest
(org.junit.runners.model.FrameworkMethod method) protected Collection<Interceptor>
protected Properties
protected List<org.junit.runners.model.FrameworkMethod>
Deprecated.Provide an implementation ofjavax.inject.Provider<Config>
instead.protected Class<?>[]
getExtraShadows
(org.junit.runners.model.FrameworkMethod frameworkMethod) protected SandboxTestRunner.HelperTestRunner
getHelperTestRunner
(Class<?> bootstrappedTestClass) protected ManifestFactory
getManifestFactory
(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
-
Field Details
-
CONFIG_PROPERTIES
- See Also:
-
-
Constructor Details
-
RobolectricTestRunner
Creates a runner to runtestClass
. Use theConfig
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 Details
-
defaultInjector
-
createClassHandler
Create aClassHandler
appropriate for the given arguments.Robolectric may chose to cache the returned instance, keyed by
shadowMap
andsandbox
.Custom TestRunner subclasses may wish to override this method to provide alternate configuration.
- Overrides:
createClassHandler
in classSandboxTestRunner
- Parameters:
shadowMap
- theShadowMap
in effect for this testsandbox
- theSdk
in effect for this test- Returns:
- an appropriate
ShadowWrangler
. - Since:
- 2.3
-
findInterceptors
- Overrides:
findInterceptors
in classSandboxTestRunner
-
createClassLoaderConfig
@Nonnull protected InstrumentationConfiguration createClassLoaderConfig(org.junit.runners.model.FrameworkMethod method) Create anInstrumentationConfiguration
suitable for the providedFrameworkMethod
.Adds configuration for Android using
AndroidConfigurer
.Custom TestRunner subclasses may wish to override this method to provide additional configuration.
- Overrides:
createClassLoaderConfig
in classSandboxTestRunner
- Parameters:
method
- the test method that's about to run- Returns:
- an
InstrumentationConfiguration
-
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 aDefaultTestLifecycle
.
-
getChildren
- Overrides:
getChildren
in classorg.junit.runners.BlockJUnit4ClassRunner
-
getSandbox
- Overrides:
getSandbox
in classSandboxTestRunner
-
beforeTest
protected void beforeTest(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod) throws Throwable - Overrides:
beforeTest
in classSandboxTestRunner
- Throws:
Throwable
-
afterTest
- Overrides:
afterTest
in classSandboxTestRunner
-
finallyAfterTest
protected void finallyAfterTest(org.junit.runners.model.FrameworkMethod method) - Overrides:
finallyAfterTest
in classSandboxTestRunner
-
getHelperTestRunner
protected SandboxTestRunner.HelperTestRunner getHelperTestRunner(Class<?> bootstrappedTestClass) throws org.junit.runners.model.InitializationError - Overrides:
getHelperTestRunner
in classSandboxTestRunner
- Throws:
org.junit.runners.model.InitializationError
-
getManifestFactory
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
-
staticGetBuildSystemApiProperties
-
createAndroidManifest
@Deprecated public static AndroidManifest createAndroidManifest(ManifestIdentifier manifestIdentifier) Deprecated.Do not use.Internal use only. -
getConfig
Deprecated.Provide an implementation ofjavax.inject.Provider<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 andConfig
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.Provide a service implementation ofGlobalConfigProvider
instead. This method will be removed in Robolectric 4.3.Provides the base Robolectric configurationConfig
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.
-
getExtraShadows
@Nonnull protected Class<?>[] getExtraShadows(org.junit.runners.model.FrameworkMethod frameworkMethod) - Overrides:
getExtraShadows
in classSandboxTestRunner
-
afterClass
protected void afterClass()- Overrides:
afterClass
in classSandboxTestRunner
-
createTest
- Overrides:
createTest
in classorg.junit.runners.BlockJUnit4ClassRunner
- Throws:
Exception
-
GlobalConfigProvider
instead.