title: How to run android instrumental test using `androidx` and `navgation architecture`?
body: <p>I'm trying to write tests for an android app. Which has one <code>Activity</code> and two <code>fragments</code> (i.e <code>FragmentOne</code> and <code>FragmentTwo</code>) by clicking a button on <code>FragmentOne</code> it goes to the <code>FragmentTwo</code>. And I wrote the test for the same and I'm using <code>androidx</code> and <code>navigation architecture</code>. I have read this <a href="https://developer.android.com/guide/navigation/navigation-testing" rel="nofollow noreferrer">link</a> and this <a href="https://developer.android.com/training/testing/set-up-project" rel="nofollow noreferrer">link</a> but didn't succeed.</p>
  
  <p>Here is my current code-</p>
  
  <p><strong>ExampleInstrumentedTest</strong></p>
  
  <pre><code>@RunWith(JUnit4::class)
  class ExampleInstrumentedTest {
  
      @Test
      fun checkSecondFrag() {
          // Create a mock NavController
          val mockNavController = mock(NavController::class.java)
  
          // Create a graphical FragmentScenario for the OneFragment
          val oneFragmentScenario = launchFragmentInContainer&lt;OneFragment&gt;()
  
          // Set the NavController property on the fragment
          oneFragmentScenario.onFragment { fragment -&gt;
              Navigation.setViewNavController(fragment.requireView(), mockNavController)
          }
  
          // Verify that performing a click prompts the correct Navigation action
          onView(ViewMatchers.withId(R.id.nextFragment)).perform(ViewActions.click())
          verify(mockNavController).navigate(R.id.action_oneFragment_to_twoFragment)
      }
  }
  </code></pre>
  
  <p><strong>Gradle(App)</strong></p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  apply plugin: 'kotlin-android'
  
  apply plugin: 'kotlin-android-extensions'
  
  android {
      compileSdkVersion 28
      defaultConfig {
          applicationId "com.varun.navtesting"
          minSdkVersion 16
          targetSdkVersion 28
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
      implementation 'androidx.appcompat:appcompat:1.0.2'
      implementation 'androidx.core:core-ktx:1.0.2'
      implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
      implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  
      // Core library
      androidTestImplementation 'androidx.test:core:1.2.0'
  
      // AndroidJUnitRunner and JUnit Rules
      androidTestImplementation 'androidx.test:runner:1.2.0'
      androidTestImplementation 'androidx.test:rules:1.2.0'
  
      // Assertions
      androidTestImplementation 'androidx.test.ext:junit:1.1.1'
      androidTestImplementation 'androidx.test.ext:truth:1.2.0'
      androidTestImplementation 'com.google.truth:truth:0.42'
  
      // Espresso dependencies
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
      androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
      androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
      androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.2.0'
      androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
      androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.2.0'
  
  
      testImplementation 'junit:junit:4.12'
  
      implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
      implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
  
      // required if you want to use Mockito for unit tests
      testImplementation 'org.mockito:mockito-core:2.25.0'
      // required if you want to use Mockito for Android tests
      androidTestImplementation 'org.mockito:mockito-android:2.19.0'
  
      // Fragment test
      implementation 'androidx.fragment:fragment:1.2.0-alpha01'
      androidTestImplementation 'androidx.fragment:fragment-testing:1.2.0-alpha01'
  
      implementation 'com.android.support:support-annotations:28.0.0'
  }
  </code></pre>
  
  <p><strong>Mainfiest</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.varun.navtesting"&gt;
  
      &lt;application
              android:allowBackup="true"
              android:icon="@mipmap/ic_launcher"
              android:label="@string/app_name"
              android:roundIcon="@mipmap/ic_launcher_round"
              android:supportsRtl="true"
              android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN"/&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER"/&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;uses-library android:name="android.test.runner"
                        android:required="false"/&gt;
  
          &lt;uses-library android:name="android.test.base"
                        android:required="false"/&gt;
          &lt;uses-library android:name="android.test.mock"
                        android:required="false"/&gt;
      &lt;/application&gt;
      &lt;instrumentation android:targetPackage="com.varun.navtesting"
                       android:name="android.test.ExampleInstrumentedTest"/&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>This line</p>
  
  <pre><code>&lt;instrumentation 
            android:targetPackage="com.varun.navtesting"
            android:name="android.test.ExampleInstrumentedTest"/&gt;
  </code></pre>
  
  <p>is showing in red color in android studio.</p>
  
  <p>Here is the
  <strong>Logcat</strong></p>
  
  <pre><code>2019-07-30 22:00:16.967 6821-6837/com.varun.navtesting E/TestRunner: failed: checkSecondFrag(com.varun.navtesting.ExampleInstrumentedTest)
  2019-07-30 22:00:16.967 6821-6837/com.varun.navtesting E/TestRunner: ----- begin exception -----
  2019-07-30 22:00:16.968 6821-6837/com.varun.navtesting E/TestRunner: java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.varun.navtesting/androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity (has extras) }
          at androidx.test.core.app.InstrumentationActivityInvoker.startActivity(InstrumentationActivityInvoker.java:344)
          at androidx.test.core.app.ActivityScenario.launchInternal(ActivityScenario.java:231)
          at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:209)
          at androidx.fragment.app.testing.FragmentScenario.internalLaunch(FragmentScenario.java:299)
          at androidx.fragment.app.testing.FragmentScenario.launchInContainer(FragmentScenario.java:282)
          at com.varun.navtesting.ExampleInstrumentedTest.checkSecondFrag(ExampleInstrumentedTest.kt:39)
          at java.lang.reflect.Method.invoke(Native Method)
          at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
          at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
          at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
          at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
          at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
          at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
          at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
          at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
          at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
          at org.junit.runners.Suite.runChild(Suite.java:128)
          at org.junit.runners.Suite.runChild(Suite.java:27)
          at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
          at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
          at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
          at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
          at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
          at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
          at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
          at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
          at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
  2019-07-30 22:00:16.968 6821-6837/com.varun.navtesting E/TestRunner: ----- end exception -----
  </code></pre>
  
  <p>Any help will be appriciated.</p>