title: Android Testing: Dialog. Check it isShowing()
body: <p>Here is my method, it works fine and shows the Dialog.</p>
  
  <pre><code>public void showDialog(){
      final Dialog dialog = new Dialog(this);
      dialog.setContentView(R.layout.mylayout);
      dialog.show();
  }
  </code></pre>
  
  <p>I have a test project and I would like to test that the Dialog is showing up. I would like to apply the .isShowing() method. Something like this...</p>
  
  <pre><code>assertTrue(dialog.isShowing());
  </code></pre>
  
  <p>But I don't know how to get to the dialog variable within my test. </p>
  
  <p>I am not using Robotium (this isn't an option for me).
  I'm currently using the ActivityUnitTestCase to test with. If any more information is required please don't hesitate to ask.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have attempted to use the answer below by making the Dialog public</p>
  
  <pre><code>public Dialog getDiag(){
      return dialog;
  }
  </code></pre>
  
  <p>Using this answer: I have a new problem when I run showDialog() in the test, it breaks when it hits: dialog.show();</p>
  
  <p>android.view.WindowManager$BadTokenException: * Unable to add window -- token null</p>