Android: Espresso doesn't wait until fragment or activity is shown so every test failed
<p>I know there are a lot of questions around this but i can't find anything to help me :(</p>

<p>I tried to use Espresso for generate UI-Test for an android app. After beating dependency issues (because some libraries are included two times in different versions as dependency from other libraries) I'm still not able to create working tests...</p>

<p>I know about IdlingResource but as I read, espresso waits out of the box till the main-thread and AsyncTaskPool is idle before running any tests.</p>

<p>For getting in touch with it I crated a simple app containing two activities, a splashscreen and a mainactivity.
The splashscreen contains something like this for waiting for three sec before starting mainActivity</p>

<pre><code> new Handler().postDelayed(new Runnable() {
   @Override
   public void run() {
     finish();
     Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
     startActivity(intent);
   }
 }, 3000);
</code></pre>

<p>I also tried to use AsyncTask for this but nothing seems to work correctly because every test fails.</p>

<p>The test only checks if a TextView containing a defined text is shown on the view by:</p>

<pre><code>onView(withText("DummyText")).check(matches(notNullValue()));
</code></pre>

<p>I thought it wouldn't be that difficult to create a simple test...</p>

<p>Because I've to test against api>=16 I need espresso. Just for me I checked it by using uiAutomator (I know it's for api >=18) but there are that smart logic to wait for something to be shown.....and that works perfectly...</p>