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.
  • Field Details

  • Constructor Details

    • SandboxTestRunner

      public SandboxTestRunner(Class<?> klass) throws org.junit.runners.model.InitializationError
      Throws:
      org.junit.runners.model.InitializationError
    • SandboxTestRunner

      public SandboxTestRunner(Class<?> klass, Injector injector) throws org.junit.runners.model.InitializationError
      Throws:
      org.junit.runners.model.InitializationError
  • Method Details

    • defaultInjector

      protected static Injector.Builder 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's Sandbox. 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 children by their associated Sandbox, and then applies the provided SandboxTestRunner.SandboxChildMapper to each group within the context of its respective sandbox.

      Parameters:
      children - The list of FrameworkMethods to be mapped.
      mapper - The SandboxTestRunner.SandboxChildMapper to apply to each group of methods.
      Returns:
      An ImmutableList containing the results of the mapping.
    • getSandboxForSandboxMapping

      protected Sandbox getSandboxForSandboxMapping(org.junit.runners.model.FrameworkMethod method)
    • findInterceptors

      @Nonnull protected Collection<Interceptor> findInterceptors()
    • getInterceptors

      @Nonnull protected Interceptors getInterceptors()
    • classBlock

      protected org.junit.runners.model.Statement classBlock(org.junit.runner.notification.RunNotifier notifier)
      Overrides:
      classBlock in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
    • afterClass

      protected void afterClass()
    • getSandbox

      @Nonnull protected Sandbox getSandbox(org.junit.runners.model.FrameworkMethod method)
    • createClassLoaderConfig

      @Nonnull protected InstrumentationConfiguration createClassLoaderConfig(org.junit.runners.model.FrameworkMethod method)
      Create an InstrumentationConfiguration suitable for the provided FrameworkMethod.

      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

      protected void configureSandbox(Sandbox sandbox, org.junit.runners.model.FrameworkMethod method)
    • methodBlock

      protected org.junit.runners.model.Statement methodBlock(org.junit.runners.model.FrameworkMethod method)
      Overrides:
      methodBlock in class org.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 FrameworkMethod from the original class loader and returns the corresponding Method instance loaded within the provided Sandbox.

      Parameters:
      sandbox - The Sandbox in which the method should be loaded.
      method - The JUnit FrameworkMethod from the original class loader.
      Returns:
      The Method instance 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

      protected void afterTest(org.junit.runners.model.FrameworkMethod method, Method bootstrappedMethod)
    • 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

      @Nonnull protected Class<?>[] getExtraShadows(org.junit.runners.model.FrameworkMethod method)
    • 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:
      withPotentialTimeout in class org.junit.runners.BlockJUnit4ClassRunner
      See Also: