title: How to test an AlertDialog in Android?
body: <p>I'm trying to test an <code>AlertDialog</code> with <code>ActivityInstrumentationTestCase2</code>.</p>
  
  <p>Here is the original code :</p>
  
  <pre><code>    this.setmBtAppelerFixe(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              AlertDialog.Builder dialog = new AlertDialog.Builder(InterventionImmobiliereDetailsActivity.this);
              dialog.setTitle("Appel");
              dialog.setMessage("Appeler le contact ?");
              dialog.setCancelable(true);
              dialog.setNegativeButton("Non", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      dialog.dismiss();
                  }
              });
              dialog.setPositiveButton("Oui", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      InterventionImmobiliereDetailsActivity.this.lancerIntentAppel(mIntervention.getTelContact());
                  }
              });
  
              mAdAppelerFixe = dialog.create();
              mAdAppelerFixe.show();
          }
      });
  </code></pre>
  
  <p>Now I can't manage to click on the Positive Button. This code doesn't seem to work :</p>
  
  <pre><code>    mActivity.runOnUiThread(new Runnable() {
          @Override
          public void run() {
              assertTrue(mLLAppelerFixe.performClick());
  
              AlertDialog mDialog = mActivity.getAdAppelerFixe();
              assertTrue(mDialog.isShowing());
  
              Button okButton = mDialog.getButton(AlertDialog.BUTTON_POSITIVE);
  
              assertTrue(okButton.performClick());
              assertTrue(mActivity.isNumeroValide());
          }
      });
  </code></pre>
  
  <p>First I perform a click on my layout to open the <code>AlertDialog</code>.
  Then I get the <code>OK_BUTTON</code> and I perform a click on it. It should set the <code>numeroValide</code> boolean at true.
  But nothing.</p>
  
  <p>How can I simply test an <code>AlertDialog</code> with buttons ?</p>