public static void setText(Instrumentation instr, final TextView view, final String text) {
    runOnMainSyncWithTimeout(
        new Callable<Void>() {
          @Override
          public Void call() {
            view.setText(text);
            return null;
          }
        });
    instr.waitForIdleSync();
    Assert.assertEquals(text, view.getText().toString());
  }
Sets the text of the provided {@link TextView} widget on the UI thread.
javatests/com/google/android/apps/authenticator/testing/TestUtilities.java