title: How to set up Mockito to mock class for Android unit test
body: <p>If I make a simple test case like</p>
  
  <pre><code>@Test
  public void myTest() throws Exception {
      Spanned word = new SpannedString("Bird");
      int length = word.length();
  }
  </code></pre>
  
  <p>an exception is thrown</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: Method length in
    android.text.SpannableStringInternal not mocked. See
    <a href="http://g.co/androidstudio/not-mocked" rel="noreferrer">http://g.co/androidstudio/not-mocked</a> for details.</p>
  </blockquote>
  
  <p>This is explained in the link above as</p>
  
  <blockquote>
    <p>The android.jar file that is used to run unit tests does not contain
    any actual code - that is provided by the Android system image on real
    devices. Instead, all methods throw exceptions (by default). This is
    to make sure your unit tests only test your code and do not depend on
    any particular behaviour of the Android platform (that you have not
    explicitly mocked e.g. using Mockito).</p>
  </blockquote>
  
  <p>So how do you set up Mockito in an Android project in order to mock classes like this?</p>
  
  <p><em>I want to learn, so I am going to add my answer below Q&amp;A style.</em></p>