title: Run runTestOnUiThread from a different class
body: <p>In our current framework we have a base class that extends ActivityInstrumentationTestCase2 | Android Developers. Typically when we write our test case classes we inherit this base class ( lets call it FooBase) and write our methods. As you can imagine this is getting really big and I would like to refactor it so that for each area of the feature we are testing it is in its own class so that we can reuse it. Hopefully my vague classes are accurate enough The goal is just being able to split the methods into different classes and call them from my testcase</p>
  
  <pre><code> public class FooBase extends ActivityInstrumentionTestCase2 {
      @Override
   public void runTestOnUiThread(Runnable runnable) {
      try {
          super.runTestOnUiThread(runnable);
      } catch (InterruptedException e) {
          throw RuntimeInterruptedException.rethrow(e);
      } catch (RuntimeException e) {
          throw e;
      } catch (Error e) {
          throw e;
      } catch (Throwable e) {
          throw new RuntimeException(e);
      }
   }
   } 
  </code></pre>
  
  <p>and our test would be eg</p>
  
  <pre><code>public class TestFooBase extends FooBase{
        public void testfeature(){
                 //execute a method that uses super.runTestOnUiThread()
        }
  
   }
  </code></pre>
  
  <p>How I attempted to refactor it</p>
  
  <pre><code> public class FooHelper extends FooBase{
       public FooHelper(Activity activity){
           setActivity(activity)
       }
       public void sameMethod(){
           //moved the method in FooBase to this class that uses the runTestOnUiThread
       }
  
  }
  </code></pre>
  
  <p>My new testcase would look something like this</p>
  
  <pre><code>public class TestFooBase extends FooBase{
        FooHelper fooHelper;
        public void setup(){
                fooHelper = new FooHelper(getActivity);
        }
        public void testfeature(){
                 //execute a method that uses super.runTestOnUiThread()
                 fooHelper.callthemethod()
        }
  
   }
  </code></pre>
  
  <p>When I execute this I get a null pointer on the super.runTestOnUIThread. </p>