title: Espresso won't find View when included with androidTestCompile
body: <p>This is darn strange. I have an <code>Activity</code> with a <code>ViewPager</code> that hosts a couple of of <code>Fragment</code>s, the first one has a <code>RadioButton</code> with the id  <code>android:id="@+id/backjudgeRadionButton"</code>. </p>
  
  <p>I have an Espresso test that looks like this: </p>
  
  <pre><code>import android.test.ActivityInstrumentationTestCase2;
  
  import model.GameSetup;
  import ui.SetupActivity;
  import weigl.fm.refwatch.R;
  
  import static android.support.test.espresso.Espresso.onView;
  import static android.support.test.espresso.action.ViewActions.click;
  import static android.support.test.espresso.matcher.ViewMatchers.withText;
  
  /**
   * Created by asco on 8/7/15.
   */
  public class SetupActivityEspressoTest extends ActivityInstrumentationTestCase2&lt;SetupActivity&gt; {
  
  
      public SetupActivityEspressoTest() {
          super(SetupActivity.class);
      }
  
  
      @Override
      protected void setUp() throws Exception {
          super.setUp();
          getActivity();
      }
  
      public void testUserRoleIsSet() {
  
  
          onView(withId(R.id.backjudgeRadionButton)).perform(click());
  
          assertEquals(GameSetup.UserRole.backjudge, getActivity().getGameSetup().getUserRole());
  
      }
  
  }
  </code></pre>
  
  <p><strong>When Espresso is imported in my <code>build.gradle</code> via</strong></p>
  
  <pre><code>compile('com.android.support.test.espresso:espresso-core:2.2') {
      exclude module: 'support-annotations'
  }
  
  compile('com.android.support.test:runner:0.3') {
      exclude module: 'support-annotations'
  }
  compile('com.android.support.test.espresso:espresso-contrib:2.2') {
      exclude module: 'support-annotations'
  }
  </code></pre>
  
  <p><strong>The test works fine.</strong> </p>
  
  <p><strong>When I use the intended variant of importing dependencies for instrumentation tests:</strong> </p>
  
  <pre><code>androidTestCompile('com.android.support.test.espresso:espresso-core:2.2') {
      exclude module: 'support-annotations'
  }
  
  androidTestCompile('com.android.support.test:runner:0.3') {
      exclude module: 'support-annotations'
  }
  androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') {
      exclude module: 'support-annotations'
  }
  </code></pre>
  
  <p><strong>with <code>androidTestCompile</code> instead of <code>compile</code> the test fails because the View with the provided id is not found:</strong> </p>
  
  <pre><code>Running tests
  Test running started
  android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with string from resource id: &lt;2131230756&gt;
  
  View Hierarchy:
  +&gt;DecorView{id=-1, visibility=VISIBLE, width=280, height=280, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
  |
  +-&gt;LinearLayout{id=-1, visibility=VISIBLE, width=280, height=280, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
  |
  +--&gt;ViewStub{id=16909171, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
  |
  +--&gt;FrameLayout{id=16908290, res-name=content, visibility=VISIBLE, width=280, height=280, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
  |
  +---&gt;LinearLayout{id=-1, visibility=VISIBLE, width=280, height=280, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
  |
  +----&gt;ViewPager{id=2131558442, res-name=viewPager, visibility=VISIBLE, width=280, height=280, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=true, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
  |
  at dalvik.system.VMStack.getThreadStackTrace(Native Method)
  at java.lang.Thread.getStackTrace(Thread.java:580)
  at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:82)
  at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:53)
  at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
  at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
  at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
  at SetupActivityEspressoTest.testUserRoleIsSet(SetupActivityEspressoTest.java:30)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  </code></pre>
  
  <p>It seems like Espresso only checks the Views in the Activity's layout, not the ones provided by the ViewPager. </p>
  
  <p>a. How comes my test works when using <code>compile</code> instead of <code>androidTestCompile</code>?</p>
  
  <p>b. Is Espresso even supposed to find <code>View</code>s within <code>Fragments</code> inside a <code>ViewPager</code>?</p>
  
  <p><strong>EDIT:</strong> 
  This is the second variant of the espresso test that I tried, taken from <a href="https://github.com/googlesamples/android-testing-templates" rel="nofollow">the new Android testing template</a>: </p>
  
  <pre><code>@RunWith(AndroidJUnit4.class)
  @LargeTest
  public class SetupActivityTest {
  
  
      @Rule
      public ActivityTestRule&lt;SetupActivity&gt; mActivityRule =
              new ActivityTestRule&lt;&gt;(SetupActivity.class);
  
      @Test
      public void findViewPerformActionAndCheckAssertion() {
          // Find Button and Click on it
          onView(withId(R.id.backjudgeRadionButton)).perform(click());
  
      }
  
  }
  </code></pre>
  
  <p>It shows the same effect. </p>
  
  <p>This is all happening inside a <code>wear</code> module if that matters. </p>
  
  <p><strong>EDIT2:</strong> You can have a look at the whole project <a href="https://github.com/asco33/RefWatch/tree/espresso2" rel="nofollow">on GitHub</a>. </p>