public class RobolectricTestRunner extends SandboxTestRunner
SandboxClassLoader
in order to provide a simulation of the
Android runtime environment.Modifier and Type | Class | Description |
---|---|---|
static class |
RobolectricTestRunner.DeprecatedTestRunnerDefaultConfigProvider |
Deprecated.
|
static class |
RobolectricTestRunner.HelperTestRunner |
|
static class |
RobolectricTestRunner.RobolectricFrameworkMethod |
Fields in this class must be serializable using XStream.
|
Modifier and Type | Field | Description |
---|---|---|
static String |
CONFIG_PROPERTIES |
classHandlerBuilder
Modifier | Constructor | Description |
---|---|---|
|
RobolectricTestRunner(Class<?> testClass) |
Creates a runner to run
testClass . |
protected |
RobolectricTestRunner(Class<?> testClass,
Injector injector) |
Modifier and Type | Method | Description |
---|---|---|
protected void |
afterClass() |
|
protected void |
afterTest(org.junit.runners.model.FrameworkMethod method,
Method bootstrappedMethod) |
|
protected void |
beforeTest(Sandbox sandbox,
org.junit.runners.model.FrameworkMethod method,
Method bootstrappedMethod) |
|
protected Config |
buildGlobalConfig() |
Deprecated.
Provide a service implementation of
GlobalConfigProvider instead. This
method will be removed in Robolectric 4.3. |
static AndroidManifest |
createAndroidManifest(ManifestIdentifier manifestIdentifier) |
Deprecated.
Do not use.
|
protected ClassHandler |
createClassHandler(ShadowMap shadowMap,
Sandbox sandbox) |
Create a
ClassHandler appropriate for the given arguments. |
protected InstrumentationConfiguration |
createClassLoaderConfig(org.junit.runners.model.FrameworkMethod method) |
Create an
InstrumentationConfiguration suitable for the provided FrameworkMethod . |
Object |
createTest() |
|
protected static Injector.Builder |
defaultInjector() |
|
protected void |
finallyAfterTest(org.junit.runners.model.FrameworkMethod method) |
|
protected Collection<Interceptor> |
findInterceptors() |
|
protected Properties |
getBuildSystemApiProperties() |
|
protected List<org.junit.runners.model.FrameworkMethod> |
getChildren() |
|
Config |
getConfig(Method method) |
Deprecated.
Provide an implementation of
Provider instead. This
method will be removed in Robolectric 4.3. |
protected ConfigurationStrategy.Configuration |
getConfiguration(Method method) |
Deprecated.
Going away before 4.2. DO NOT SHIP.
|
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> |
getTestLifecycleClass() |
An instance of the returned class will be created for each test invocation.
|
protected static Properties |
staticGetBuildSystemApiProperties() |
collectInitializationErrors, computeTestMethods, describeChild, getTestRules, isIgnored, methodInvoker, possiblyExpectingExceptions, rules, runChild, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withBefores
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
childrenInvoker, classRules, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, run, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClasses
classBlock, configureSandbox, getInterceptors, methodBlock, withPotentialTimeout
public static final String CONFIG_PROPERTIES
public RobolectricTestRunner(Class<?> testClass) throws org.junit.runners.model.InitializationError
testClass
. Use the Config
annotation to configure.testClass
- the test class to be runorg.junit.runners.model.InitializationError
- if junit says soprotected static Injector.Builder defaultInjector()
@Nonnull protected ClassHandler createClassHandler(ShadowMap shadowMap, Sandbox sandbox)
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.
createClassHandler
in class SandboxTestRunner
shadowMap
- the ShadowMap
in effect for this testsandbox
- the Sdk
in effect for this testShadowWrangler
.@Nonnull protected Collection<Interceptor> findInterceptors()
findInterceptors
in class SandboxTestRunner
@Nonnull protected InstrumentationConfiguration createClassLoaderConfig(org.junit.runners.model.FrameworkMethod method)
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.
createClassLoaderConfig
in class SandboxTestRunner
method
- the test method that's about to runInstrumentationConfiguration
@Nonnull protected Class<? extends TestLifecycle> getTestLifecycleClass()
Custom TestRunner subclasses may wish to override this method to provide alternate configuration.
TestLifecycle
. This implementation returns a DefaultTestLifecycle
.protected List<org.junit.runners.model.FrameworkMethod> getChildren()
getChildren
in class org.junit.runners.BlockJUnit4ClassRunner
@Nonnull protected AndroidSandbox getSandbox(org.junit.runners.model.FrameworkMethod method)
getSandbox
in class SandboxTestRunner
protected void beforeTest(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod) throws Throwable
beforeTest
in class SandboxTestRunner
Throwable
protected void afterTest(org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod)
afterTest
in class SandboxTestRunner
protected void finallyAfterTest(org.junit.runners.model.FrameworkMethod method)
finallyAfterTest
in class SandboxTestRunner
protected SandboxTestRunner.HelperTestRunner getHelperTestRunner(Class bootstrappedTestClass)
getHelperTestRunner
in class SandboxTestRunner
protected ManifestFactory getManifestFactory(Config config)
Custom TestRunner subclasses may wish to override this method to provide alternate configuration.
config
- Specification of the SDK version, manifest file, package name, etc.protected Properties getBuildSystemApiProperties()
protected static Properties staticGetBuildSystemApiProperties()
@Deprecated public static AndroidManifest createAndroidManifest(ManifestIdentifier manifestIdentifier)
@Deprecated public Config getConfig(Method method)
Provider
instead. This
method will be removed in Robolectric 4.3.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.
method
- the test method@Deprecated protected ConfigurationStrategy.Configuration getConfiguration(Method method)
Temporarily visible for migration.
@Deprecated protected Config buildGlobalConfig()
GlobalConfigProvider
instead. This
method will be removed in Robolectric 4.3.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.
Config
object@Nonnull protected Class<?>[] getExtraShadows(org.junit.runners.model.FrameworkMethod frameworkMethod)
getExtraShadows
in class SandboxTestRunner
protected void afterClass()
afterClass
in class SandboxTestRunner