title: Espresso with AsyncTask
body: <p>I'm trying to write a test for my SignIn Activity, in which I'm using an AsyncTask.</p>
  
  <pre><code>public class SignInActivity extends Activity{
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      .........
  
      new AsyncSignButton().execute();
  }
  
  class AsyncSignButton extends AsyncTask&lt;Void, Void, Integer&gt;{
     ....... 
  }
  </code></pre>
  
  <p>For testing, I have tried using IdlingResource, but I do not understand how would use it with an AsyncTask, not with a WebView as in the examples, just simple a AsyncTask.</p>
  
  <hr>
  
  <p>Here is my Test code:</p>
  
  <pre><code>public class Test extends ActivityInstrumentationTestCase2&lt;SplashActivity&gt; {
  
  private SplashActivity mActivity;
  
  public Test(){
      super(SplashActivity.class);
  }
  
  public Test(Class&lt;SplashActivity&gt; activityClass) {
      super(activityClass);
  }
  
  @Override
  protected void setUp() throws Exception{
      super.setUp();
      mActivity = getActivity();
      //how call it?
  }
  
  @LargeTest
  public void testList() throws InterruptedException {
  
     //wait AsyncTask before call
     onView(withId(R.id.action_bar_accept_button)).perform(click());
  
  }
  
  public final class AsyncIdlingResource implements IdlingResource {
  
      private AsyncTask asyncTask;
      private ResourceCallback callback;
  
      public AsyncIdlingResource(AsyncTask asyncTask){
          this.asyncTask = checkNotNull(asyncTask);
      }
  
      @Override
      public String getName() {
          return "Sign idling resource";
      }
  
      @Override
      public boolean isIdleNow() {
          if(asyncTask == null) return true;
          return asyncTask.getStatus() == AsyncTask.Status.FINISHED;
      }
  
      @Override
      public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
          this.callback = resourceCallback;
      }
  }
  
  }
  </code></pre>