Class SandboxTestRunner.HelperTestRunner

java.lang.Object
org.junit.runner.Runner
org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
org.junit.runners.BlockJUnit4ClassRunner
org.robolectric.internal.SandboxTestRunner.HelperTestRunner
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.HelperTestRunner
Enclosing class:
SandboxTestRunner

protected static class SandboxTestRunner.HelperTestRunner extends org.junit.runners.BlockJUnit4ClassRunner
The goal of SandboxTestRunner.HelperTestRunner is to have BlockJUnit4ClassRunner instances that encapsulate bootstrapped test classes. When SandboxTestRunner is initially constructed, the test class is from the main app class loader. This test class can't be used to run tests because it can't load Android classes.

Because we need load a separate test class per sandbox, we need to create a new Runner that encapsulates the bootstrapped test class. This is primarily used to invoke the ParentRunner#methodBlock(FrameworkMethod), which uses reflection to invoke before/after methods and test rules.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    org.junit.runners.model.FrameworkMethod
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    List<org.junit.rules.TestRule>
     
    protected org.junit.runners.model.Statement
    methodBlock(org.junit.runners.model.FrameworkMethod method)
     
    protected org.junit.runners.model.Statement
    methodInvoker(org.junit.runners.model.FrameworkMethod method, Object test)
    For tests with a timeout, we need to wrap the test method execution (but not @Befores or @Afters in a TimeLimitedStatement.
    protected String
    testName(org.junit.runners.model.FrameworkMethod method)
     
    protected org.junit.runners.model.Statement
    withAfterClasses(org.junit.runners.model.Statement statement)
     
    protected org.junit.runners.model.Statement
    withBeforeClasses(org.junit.runners.model.Statement statement)
     
    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.

    Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner

    collectInitializationErrors, computeTestMethods, createTest, createTest, describeChild, getChildren, getTestRules, isIgnored, possiblyExpectingExceptions, rules, runChild, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withBefores

    Methods inherited from class org.junit.runners.ParentRunner

    childrenInvoker, classBlock, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, order, run, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withInterruptIsolation

    Methods inherited from class org.junit.runner.Runner

    testCount

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • frameworkMethod

      public org.junit.runners.model.FrameworkMethod frameworkMethod
  • Constructor Details

    • HelperTestRunner

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

    • methodBlock

      protected org.junit.runners.model.Statement methodBlock(org.junit.runners.model.FrameworkMethod method)
      Overrides:
      methodBlock in class org.junit.runners.BlockJUnit4ClassRunner
    • classRules

      public List<org.junit.rules.TestRule> classRules()
      Overrides:
      classRules in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
    • withAfterClasses

      protected org.junit.runners.model.Statement withAfterClasses(org.junit.runners.model.Statement statement)
      Overrides:
      withAfterClasses in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
    • withBeforeClasses

      protected org.junit.runners.model.Statement withBeforeClasses(org.junit.runners.model.Statement statement)
      Overrides:
      withBeforeClasses in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
    • methodInvoker

      protected org.junit.runners.model.Statement methodInvoker(org.junit.runners.model.FrameworkMethod method, Object test)
      For tests with a timeout, we need to wrap the test method execution (but not @Befores or @Afters in a TimeLimitedStatement. JUnit's built-in FailOnTimeout statement causes the test method (but not @Befores or @Afters) to be run on a short-lived thread. This is inadequate for our purposes; we want to guarantee that every entry point to test code is run from the same thread.
      Overrides:
      methodInvoker in class org.junit.runners.BlockJUnit4ClassRunner
    • 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:
    • testName

      protected String testName(org.junit.runners.model.FrameworkMethod method)
      Overrides:
      testName in class org.junit.runners.BlockJUnit4ClassRunner