public class RobolectricTestRunner extends SandboxTestRunner
Loads and runs a test in a SandboxClassLoader
in order to provide a simulation of the Android runtime environment.
Modifier and Type | Class and Description |
---|---|
static class |
RobolectricTestRunner.DeprecatedTestRunnerDefaultConfigProvider
Deprecated.
|
static class |
RobolectricTestRunner.HelperTestRunner |
Modifier and Type | Field and Description |
---|---|
static String |
CONFIG_PROPERTIES |
Modifier | Constructor and Description |
---|---|
|
RobolectricTestRunner(Class<?> testClass)
Creates a runner to run
testClass . |
protected |
RobolectricTestRunner(Class<?> testClass,
Injector injector) |
Modifier and Type | Method and 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. See Migration Notes for details. 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
javax.inject.Provider instead. See Migration Notes for details. 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() |
classBlock, configureSandbox, createShadowMap, getInterceptors, methodBlock, withPotentialTimeout
collectInitializationErrors, computeTestMethods, describeChild, getTestRules, isIgnored, methodInvoker, possiblyExpectingExceptions, rules, runChild, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withBefores
public static final String CONFIG_PROPERTIES
public RobolectricTestRunner(Class<?> testClass) throws org.junit.runners.model.InitializationError
Creates a runner to run 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)
Create a ClassHandler
appropriate for the given arguments.
Robolectric may chose to cache the returned instance, keyed by shadowMap and sdk.
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 testClassHandler
. This implementation returns a ShadowWrangler
.@Nonnull protected Collection<Interceptor> findInterceptors()
findInterceptors
in class SandboxTestRunner
@Nonnull protected 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.
createClassLoaderConfig
in class SandboxTestRunner
method
- the test method that’s about to runInstrumentationConfiguration
@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.
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)
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.
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)
Internal use only.
@Deprecated public Config getConfig(Method method)
javax.inject.Provider
instead. See Migration Notes for details. 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.
method
- the test method@Deprecated protected ConfigurationStrategy.Configuration getConfiguration(Method method)
Calculate the configuration for a given test method.
Temporarily visible for migration.
@Deprecated protected Config buildGlobalConfig()
GlobalConfigProvider
instead. See Migration Notes for details. 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.
Config
object@Nonnull protected Class<?>[] getExtraShadows(org.junit.runners.model.FrameworkMethod frameworkMethod)
getExtraShadows
in class SandboxTestRunner
protected void afterClass()
afterClass
in class SandboxTestRunner