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.HelperTestRunner |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CONFIG_PROPERTIES |
| Constructor and Description |
|---|
RobolectricTestRunner(java.lang.Class<?> testClass)
Creates a runner to run
testClass. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterClass() |
protected void |
afterTest(org.junit.runners.model.FrameworkMethod method,
java.lang.reflect.Method bootstrappedMethod) |
protected void |
beforeTest(Sandbox sandbox,
org.junit.runners.model.FrameworkMethod method,
java.lang.reflect.Method bootstrappedMethod) |
protected Config |
buildGlobalConfig()
Provides the base Robolectric configuration
Config used for all tests. |
protected void |
configureSandbox(Sandbox sandbox,
org.junit.runners.model.FrameworkMethod method) |
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. |
protected SdkPicker |
createSdkPicker()
Create a
SdkPicker for determining which SDKs will be tested. |
java.lang.Object |
createTest() |
protected void |
finallyAfterTest(org.junit.runners.model.FrameworkMethod method) |
protected java.util.Collection<Interceptor> |
findInterceptors() |
protected java.util.Properties |
getBuildSystemApiProperties() |
protected java.util.List<org.junit.runners.model.FrameworkMethod> |
getChildren() |
Config |
getConfig(java.lang.reflect.Method method)
Compute the effective Robolectric configuration for a given test method.
|
protected java.lang.Class<?>[] |
getExtraShadows(org.junit.runners.model.FrameworkMethod frameworkMethod) |
protected SandboxTestRunner.HelperTestRunner |
getHelperTestRunner(java.lang.Class bootstrappedTestClass) |
protected DependencyResolver |
getJarResolver() |
protected ManifestFactory |
getManifestFactory(Config config)
Detects which build system is in use and returns the appropriate ManifestFactory implementation.
|
protected SdkEnvironment |
getSandbox(org.junit.runners.model.FrameworkMethod method) |
protected SandboxFactory |
getSandboxFactory() |
protected java.lang.Class<? extends TestLifecycle> |
getTestLifecycleClass()
An instance of the returned class will be created for each test invocation.
|
protected void |
internalAfterTest(org.junit.runners.model.FrameworkMethod frameworkMethod,
java.lang.reflect.Method method) |
protected boolean |
shouldIgnore(org.junit.runners.model.FrameworkMethod method) |
classBlock, createShadowMap, getInterceptors, getPerfStatsReporters, methodBlock, runChildcollectInitializationErrors, computeTestMethods, describeChild, getTestRules, isIgnored, methodInvoker, possiblyExpectingExceptions, rules, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withBefores, withPotentialTimeoutpublic static final java.lang.String CONFIG_PROPERTIES
public RobolectricTestRunner(java.lang.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 DependencyResolver getJarResolver()
@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 sdkConfig.
Custom TestRunner subclasses may wish to override this method to provide alternate configuration.
createClassHandler in class SandboxTestRunnershadowMap - the ShadowMap in effect for this testsandbox - the SdkConfig in effect for this testClassHandler. This implementation returns a ShadowWrangler.@Nonnull protected SdkPicker createSdkPicker()
Create a SdkPicker for determining which SDKs will be tested.
Custom TestRunner subclasses may wish to override this method to provide alternate configuration.
SdkPicker.@Nonnull protected java.util.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 SandboxTestRunnermethod - the test method that’s about to runInstrumentationConfigurationprotected void configureSandbox(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method)
configureSandbox in class SandboxTestRunner@Nonnull protected java.lang.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 java.util.List<org.junit.runners.model.FrameworkMethod> getChildren()
getChildren in class org.junit.runners.BlockJUnit4ClassRunnerprotected boolean shouldIgnore(org.junit.runners.model.FrameworkMethod method)
shouldIgnore in class SandboxTestRunner@Nonnull protected SdkEnvironment getSandbox(org.junit.runners.model.FrameworkMethod method)
getSandbox in class SandboxTestRunnerprotected SandboxFactory getSandboxFactory()
protected void beforeTest(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method, java.lang.reflect.Method bootstrappedMethod) throws java.lang.Throwable
beforeTest in class SandboxTestRunnerjava.lang.Throwableprotected void afterTest(org.junit.runners.model.FrameworkMethod method,
java.lang.reflect.Method bootstrappedMethod)
afterTest in class SandboxTestRunnerprotected void finallyAfterTest(org.junit.runners.model.FrameworkMethod method)
finallyAfterTest in class SandboxTestRunnerprotected SandboxTestRunner.HelperTestRunner getHelperTestRunner(java.lang.Class bootstrappedTestClass)
getHelperTestRunner in class SandboxTestRunnerprotected 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 java.util.Properties getBuildSystemApiProperties()
@Deprecated public static AndroidManifest createAndroidManifest(ManifestIdentifier manifestIdentifier)
Internal use only.
public Config getConfig(java.lang.reflect.Method method)
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 methodprotected Config buildGlobalConfig()
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 java.lang.Class<?>[] getExtraShadows(org.junit.runners.model.FrameworkMethod frameworkMethod)
getExtraShadows in class SandboxTestRunnerprotected void internalAfterTest(org.junit.runners.model.FrameworkMethod frameworkMethod,
java.lang.reflect.Method method)
protected void afterClass()
afterClass in class SandboxTestRunnerpublic java.lang.Object createTest()
throws java.lang.Exception
createTest in class org.junit.runners.BlockJUnit4ClassRunnerjava.lang.Exception