title: When running Kotlin Unit and UI tests, 1 or 2 new tests are failing everything time
body: <p>I am trying to run both unit and UI testing in Kotlin using Junit and Espresso. 
  What is really interesting is that everytime I run the entire test, 1 or 2 new tests are failing. 
  It seems that there is a systematic glitch in my test settings. What would be the cause of this issue? Any suggestions where i should begin debugging?</p>
  
  <p>Test Setting:</p>
  
  <pre><code>// Build.gradle
  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.recyclerview:recyclerview:1.0.0"
      implementation 'androidx.cardview:cardview:1.0.0'
      implementation 'androidx.legacy:legacy-support-v4:1.0.0'
      implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
      implementation 'androidx.navigation:navigation-fragment:2.0.0'
      implementation 'androidx.navigation:navigation-ui:2.0.0'
      implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
      implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
      implementation 'androidx.room:room-runtime:2.1.0'
      implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
      kapt 'androidx.room:room-compiler:2.1.0'
  
      // test implementation
      testImplementation 'junit:junit:4.12'
      testImplementation 'org.powermock:powermock-module-junit4:1.7.4'
      testImplementation 'org.powermock:powermock-api-mockito2:1.7.4'
  
      androidTestImplementation 'androidx.test.ext:junit:1.1.1'
      androidTestImplementation 'androidx.test:runner:1.2.0'
      androidTestImplementation 'androidx.test:rules:1.2.0'
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
      androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
  
      implementation 'com.google.code.gson:gson:2.8.5'
      implementation 'com.squareup.retrofit2:retrofit:2.6.0'
      implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
  }
  </code></pre>
  
  <p>Several types of error message that I am facing in this issue:</p>
  
  <p>type 1: </p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: xyz.hitit.userapplication.debug, PID: 11286
      java.lang.IllegalStateException: pwdEditText must not be null
          at xyz.hitit.userapplication.ui.registrationLogin.PasswordLoginFragment$onCreateView$1$1$1.run(PasswordLoginFragment.kt:72)
          at android.os.Handler.handleCallback(Handler.java:883)
          at android.os.Handler.dispatchMessage(Handler.java:100)
          at android.os.Looper.loop(Looper.java:214)
          at android.app.ActivityThread.main(ActivityThread.java:7356)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
  E/MonitoringInstr: Exception encountered by: Thread[main,5,main]. Dumping thread state to outputs and pining for the fjords.
      java.lang.IllegalStateException: pwdEditText must not be null
          at xyz.hitit.userapplication.ui.registrationLogin.PasswordLoginFragment$onCreateView$1$1$1.run(PasswordLoginFragment.kt:72)
          at android.os.Handler.handleCallback(Handler.java:883)
          at android.os.Handler.dispatchMessage(Handler.java:100)
          at android.os.Looper.loop(Looper.java:214)
          at android.app.ActivityThread.main(ActivityThread.java:7356)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
  </code></pre>
  
  <p>type 2: </p>
  
  <pre><code>androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (Child at position 1 in parent (with id: xyz.hitit.userapplication.debug:id/design_navigation_view and Child at position 0 in parent with id: xyz.hitit.userapplication.debug:id/nav_view) and is displayed on the screen to the user)
  
  View Hierarchy:
  +&gt;DecorView{id=-1, visibility=VISIBLE, width=1080, height=2160, 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, layout-params={(0,0)(fillxfill) ty=BASE_APPLICATION wanim=0x10302fe
  fl=LAYOUT_IN_SCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED DRAWS_SYSTEM_BAR_BACKGROUNDS
  pfl=FORCE_DRAW_STATUS_BAR_BACKGROUND}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
  |
  +-&gt;LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=2028, 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, layout-params=android.widget.FrameLayout$LayoutParams@cf89f9f, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
  (133 more lines...)
  </code></pre>
  
  <p>type 3: </p>
  
  <pre><code>androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: is "randomTextToShowXButton"' doesn't match the selected view.
  Expected: with text: is "randomTextToShowXButton"
  Got: "ClearEditText{id=2131230812, res-name=emailEditText, visibility=VISIBLE, width=938, height=132, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=true, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.constraintlayout.widget.ConstraintLayout$LayoutParams@bbfd43f, tag=null, root-is-layout-requested=false, has-input-connection=true, editor-info=[inputType=0x21 imeOptions=0x6 privateImeOptions=null actionLabel=null actionId=0 initialSelStart=19 initialSelEnd=19 initialCapsMode=0x0 hintText=youremail@email.com label=null packageName=null fieldId=0 fieldName=null extras=null hintLocales=null contentMimeTypes=null ], x=71.0, y=572.0, text=randomTextToShowXBu, hint=youremail@email.com, input-type=33, ime-target=true, has-links=false}"
  
  at dalvik.system.VMStack.getThreadStackTrace(Native Method)
  at java.lang.Thread.getStackTrace(Thread.java:1720)
  at androidx.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:96)
  at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:59)
  (51 more lines...)
  </code></pre>
  
  <p>type 4: </p>
  
  <pre><code>java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
  at androidx.fragment.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:2080)
  at androidx.fragment.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2106)
  at androidx.fragment.app.BackStackRecord.commitInternal(BackStackRecord.java:683)
  at androidx.fragment.app.BackStackRecord.commit(BackStackRecord.java:637)
  at xyz.hitit.userapplication.ui.registrationLogin.RegisterLoginActivity$onCreate$1.invoke(RegisterLoginActivity.kt:42)
  at xyz.hitit.userapplication.ui.registrationLogin.RegisterLoginActivity$onCreate$1.invoke(RegisterLoginActivity.kt:14)
  at xyz.hitit.api.methods.OAuth$requestJWTClientCredentials$1.onResponse(OAuth.kt:37)
  (8 more lines...)
  </code></pre>