Package org.robolectric.internal
Class SandboxTestRunner
java.lang.Object
org.junit.runner.Runner
org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
org.junit.runners.BlockJUnit4ClassRunner
org.robolectric.internal.SandboxTestRunner
- All Implemented Interfaces:
org.junit.runner.Describable,org.junit.runner.manipulation.Filterable,org.junit.runner.manipulation.Orderable,org.junit.runner.manipulation.Sortable
- Direct Known Subclasses:
RobolectricTestRunner
public class SandboxTestRunner
extends org.junit.runners.BlockJUnit4ClassRunner
Sandbox test runner that runs each test in a sandboxed class loader environment. Typically, this
runner should not be directly accessed, use
RobolectricTestRunner
instead.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThe goal ofSandboxTestRunner.HelperTestRunneris to haveBlockJUnit4ClassRunnerinstances that encapsulate bootstrapped test classes.protected static interfaceAn interface used bymapChildrenInSandbox(List, SandboxChildMapper)to map a list ofFrameworkMethods within a specificSandbox. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected final ClassHandlerBuilderprotected final List<MethodHandleDecorator> -
Constructor Summary
ConstructorsConstructorDescriptionSandboxTestRunner(Class<?> klass) SandboxTestRunner(Class<?> klass, Injector injector) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidprotected voidbeforeTest(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod) protected org.junit.runners.model.StatementclassBlock(org.junit.runner.notification.RunNotifier notifier) protected voidconfigureSandbox(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method) protected ClassHandlercreateClassHandler(ShadowMap shadowMap, Sandbox sandbox, List<MethodHandleDecorator> decorators) protected InstrumentationConfigurationcreateClassLoaderConfig(org.junit.runners.model.FrameworkMethod method) Create anInstrumentationConfigurationsuitable for the providedFrameworkMethod.protected static Injector.Builderprotected voidfinallyAfterTest(org.junit.runners.model.FrameworkMethod method) protected Collection<Interceptor> protected static MethodgetBootstrappedMethod(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method) Retrieves the sandboxed version of a test method.protected Class<?>[]getExtraShadows(org.junit.runners.model.FrameworkMethod method) protected SandboxTestRunner.HelperTestRunnergetHelperTestRunner(Class<?> bootstrappedTestClass) protected Interceptorsprotected SandboxgetSandbox(org.junit.runners.model.FrameworkMethod method) protected SandboxgetSandboxForSandboxMapping(org.junit.runners.model.FrameworkMethod method) protected com.google.common.collect.ImmutableList<org.junit.runners.model.FrameworkMethod> mapChildrenInSandbox(List<org.junit.runners.model.FrameworkMethod> children, SandboxTestRunner.SandboxChildMapper mapper) Provides a mechanism for test runners to perform test discovery or other operations within the context of each test'sSandbox.protected org.junit.runners.model.StatementmethodBlock(org.junit.runners.model.FrameworkMethod method) protected org.junit.runners.model.StatementwithPotentialTimeout(org.junit.runners.model.FrameworkMethod method, Object test, org.junit.runners.model.Statement next) Disables JUnit's normal timeout mode strategy.Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner
collectInitializationErrors, computeTestMethods, createTest, createTest, describeChild, getChildren, getTestRules, isIgnored, methodInvoker, possiblyExpectingExceptions, rules, runChild, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withBeforesMethods inherited from class org.junit.runners.ParentRunner
childrenInvoker, classRules, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, order, run, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClasses, withInterruptIsolationMethods inherited from class org.junit.runner.Runner
testCount
-
Field Details
-
CLASS_NAME_JUNIT_JUPITER_TEST
- See Also:
-
classHandlerBuilder
-
decorators
-
-
Constructor Details
-
Method Details
-
defaultInjector
-
mapChildrenInSandbox
protected com.google.common.collect.ImmutableList<org.junit.runners.model.FrameworkMethod> mapChildrenInSandbox(List<org.junit.runners.model.FrameworkMethod> children, SandboxTestRunner.SandboxChildMapper mapper) Provides a mechanism for test runners to perform test discovery or other operations within the context of each test'sSandbox. This is particularly useful for runners that need access to the Android environment during test discovery, such as parameterizing runners that invoke methods on the test class to generate test cases.The method groups the given
childrenby their associatedSandbox, and then applies the providedSandboxTestRunner.SandboxChildMapperto each group within the context of its respective sandbox.- Parameters:
children- The list ofFrameworkMethods to be mapped.mapper- TheSandboxTestRunner.SandboxChildMapperto apply to each group of methods.- Returns:
- An
ImmutableListcontaining the results of the mapping.
-
getSandboxForSandboxMapping
-
findInterceptors
-
getInterceptors
-
classBlock
protected org.junit.runners.model.Statement classBlock(org.junit.runner.notification.RunNotifier notifier) - Overrides:
classBlockin classorg.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
-
afterClass
protected void afterClass() -
getSandbox
-
createClassLoaderConfig
@Nonnull protected InstrumentationConfiguration createClassLoaderConfig(org.junit.runners.model.FrameworkMethod method) Create anInstrumentationConfigurationsuitable for the providedFrameworkMethod.Custom TestRunner subclasses may wish to override this method to provide alternate configuration.
- Parameters:
method- the test method that's about to run- Returns:
- an
InstrumentationConfiguration
-
configureSandbox
-
methodBlock
protected org.junit.runners.model.Statement methodBlock(org.junit.runners.model.FrameworkMethod method) - Overrides:
methodBlockin classorg.junit.runners.BlockJUnit4ClassRunner
-
getBootstrappedMethod
protected static Method getBootstrappedMethod(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method) Retrieves the sandboxed version of a test method.When running tests in a sandbox, the classes are loaded by a special class loader. This method takes a
FrameworkMethodfrom the original class loader and returns the correspondingMethodinstance loaded within the providedSandbox.- Parameters:
sandbox- TheSandboxin which the method should be loaded.method- The JUnitFrameworkMethodfrom the original class loader.- Returns:
- The
Methodinstance representing the same method within the sandbox's class loader. - Throws:
RuntimeException- if the method cannot be found in the bootstrapped class.
-
beforeTest
protected void beforeTest(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod) throws Throwable - Throws:
Throwable
-
afterTest
-
finallyAfterTest
protected void finallyAfterTest(org.junit.runners.model.FrameworkMethod method) -
getHelperTestRunner
protected SandboxTestRunner.HelperTestRunner getHelperTestRunner(Class<?> bootstrappedTestClass) throws org.junit.runners.model.InitializationError - Throws:
org.junit.runners.model.InitializationError
-
getExtraShadows
-
createClassHandler
@Nonnull protected ClassHandler createClassHandler(ShadowMap shadowMap, Sandbox sandbox, List<MethodHandleDecorator> decorators) -
withPotentialTimeout
protected org.junit.runners.model.Statement withPotentialTimeout(org.junit.runners.model.FrameworkMethod method, Object test, org.junit.runners.model.Statement next) Disables JUnit's normal timeout mode strategy.- Overrides:
withPotentialTimeoutin classorg.junit.runners.BlockJUnit4ClassRunner- See Also:
-