public static String enterText(
      Instrumentation instr, final EditText editText, final String text) {
    runOnMainSyncWithTimeout(
        new Callable<Void>() {
          @Override
          public Void call() {
            editText.requestFocus();
            return null;
          }
        });
    // TODO: Decide on using touch mode and how to do it consistently. e.g. the above could be
    // replaced by "TouchUtils.tapView(this, editText);"
    instr.sendStringSync(text);
    return editText.getText().toString();
  }
Sets the text of the provided {@link TextView} widget on the UI thread.
javatests/com/google/android/apps/authenticator/testing/TestUtilities.java