title: Simple Espresso test "Looped for x iterations over 60sec" error
body: <p>I actually tried to setup some unit test with Espresso and after some hours of research the app do only the click and get focus by the EditText but after that there is nothing</p>
  
  <pre><code>Caused by: android.support.test.espresso.AppNotIdleException: Looped for 1996 iterations over 60 SECONDS. The following Idle Conditions failed .
  </code></pre>
  
  <p>i've removed all animation &amp; SwipeRefreshLayout cause i saw there is a bug with the swiperefresh</p>
  
  <p>I actually use some callback for replace the current fragment in the Activity</p>
  
  <p>if someone have some tips i'm out after 4 hours of searching u_u</p>
  
  <p>Thanks you :)</p>
  
  <hr>
  
  <p>My Gradle dependencies :</p>
  
  <pre><code>// App dependencies
  compile 'com.android.support:support-annotations:23.3.0'
  compile 'com.google.guava:guava:18.0'
  // Testing-only dependencies
  // Force usage of support annotations in the test app, since it is internally used by the runner module.
  androidTestCompile 'com.android.support:support-annotations:23.3.0'
  androidTestCompile 'com.android.support.test:runner:0.4.1'
  androidTestCompile 'com.android.support.test:rules:0.4.1'
  androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
  androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'
  </code></pre>
  
  <p>I've added this on the defaultConfig :</p>
  
  <pre><code>testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  </code></pre>
  
  <p>There is my test :</p>
  
  <pre><code>@RunWith(AndroidJUnit4.class)
  @LargeTest
  public class HelloWorldEspressoTest {
  
      public static final String USERNAME = "do_f";
  
      @Rule
      public ActivityTestRule&lt;LoginActivity&gt; mActivityRule = new ActivityTestRule(LoginActivity.class);
  
      private LoginActivity mActivity = null;
  
      @Before
      public void setActivity() {
          mActivity = mActivityRule.getActivity();
      }
  
      @Test
      public void login_LoginActivity() {
  
          onView(withId(R.id.menu_login)).perform(click());
  
          onView(withId(R.id.login_username))
                  .perform(typeText(USERNAME), closeSoftKeyboard());
      }
  }
  </code></pre>
  
  <p>There is my activity : </p>
  
  <pre><code>public class LoginActivity extends AppCompatActivity
          implements MenuFragment.OnFragmentInteractionListener {
  
      private FragmentManager fm;
  
      public static void newActivity(Activity activity)
      {
          Intent i = new Intent(activity, LoginActivity.class);
          activity.startActivity(i);
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
          SharedPreferences sp = getSharedPreferences(Utils.SP, Context.MODE_PRIVATE);
  
          if (!sp.getString(Utils.TOKEN, "null").equals("null"))
          {
              MainActivity.newActivity(this);
              finish();
          }
  
          fm = getFragmentManager();
          fm.beginTransaction()
                  .replace(R.id.container, MenuFragment.newInstance())
                  .addToBackStack(null)
                  .commit();
      }
  
      @Override
      public void onBackPressed()
      {
          if (getFragmentManager().getBackStackEntryCount() &gt; 1)
              getFragmentManager().popBackStack();
          else
              super.onBackPressed();
      }
  
      @Override
      public void showLogin() {
          fm.beginTransaction()
                  .replace(R.id.container, LoginFragment.newInstance())
                  .addToBackStack(null)
                  .commit();
      }
  
      @Override
      public void showRegister() {
          fm.beginTransaction()
                  .replace(R.id.container, RegisterFragment.newInstance())
                  .addToBackStack(null)
                  .commit();
      }
  }
  </code></pre>
  
  <p>And my LoginFragment : </p>
  
  <pre><code>    private static final String        TAG = "LoginFragment";
  
  @Bind(R.id.loading_spinner)
  ProgressBar loading;
  
  @Bind(R.id.content)
  LinearLayout content;
  
  @Bind(R.id.login_username)
  EditText        username;
  
  @Bind(R.id.login_password)
  EditText        password;
  
  public LoginFragment() {
  
  }
  
  public static LoginFragment newInstance() {
      return new LoginFragment();
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View v = inflater.inflate(R.layout.login_fragment_login, container, false);
      ButterKnife.bind(this, v);
      return v;
  }
  
  @Override
  public void onActivityCreated(Bundle saveInstanceState) {
      super.onActivityCreated(saveInstanceState);
  }
  
  @OnClick(R.id.login_submit)
  public void onSubmit(View v)
  {
      if (username.getText().length() == 0
              || password.getText().length() == 0)
      {
          Snackbar.make(getView(), "blabla", Snackbar.LENGTH_SHORT).show();
          return ;
      }
      //hideContent();
      LoginPost p = new LoginPost(username.getText().toString(), password.getText().toString());
      Call&lt;LoginResponse&gt; call = RestClient.get().login(p);
      call.enqueue(new Callback&lt;LoginResponse&gt;() {
          @Override
          public void onResponse(Call&lt;LoginResponse&gt; call, Response&lt;LoginResponse&gt; response) {
              if (response.body() == null) {
                  String msg = getResources().getString(R.string.login_error_bad_credentials);
                  Snackbar.make(getView(), msg, Snackbar.LENGTH_SHORT).show();
                  //showContent();
              } else {
                  SharedPreferences sp = getActivity().getSharedPreferences(Utils.SP, Context.MODE_PRIVATE);
                  sp.edit().putString(Utils.TOKEN, response.body().getToken()).apply();
                  sp.edit().putString(Utils.USERNAME, username.getText().toString()).apply();
                  MainActivity.newActivity(getActivity());
                  getActivity().finish();
              }
          }
  
          @Override
          public void onFailure(Call&lt;LoginResponse&gt; call, Throwable t) {
              Snackbar.make(getView(), "onFailure", Snackbar.LENGTH_SHORT).show();
              //showContent();
          }
      });
  }
  </code></pre>