title: How to unit test custom view with attribute
body: <p>I'm having trouble to create a unit test for my custom view.  I try to add an attribute and test it if my custom view class get it right.</p>
  
  <p>Here's what my test looks like:</p>
  
  <pre class="lang-java prettyprint-override"><code>@RunWith(AndroidJUnit4.class)
  @SmallTest
  public class BaseRatingBarMinRatingTest {
  
      private Context mContext;
  
      @Before
      public void setUp(){
          mContext = InstrumentationRegistry.getTargetContext();
      }
  
      @Test
      public void constructor_should_setMinRating_when_attriSetHasOne() throws Exception{
          // 1. ARRANGE DATA
          float minRating = 2.5f;
          AttributeSet as = mock(AttributeSet.class);
          when(as.getAttributeFloatValue(eq(R.styleable.BaseRatingBar_srb_minRating), anyFloat())).thenReturn(minRating);
  
  
          // 2. ACT
          BaseRatingBar brb = new BaseRatingBar(mContext, as);
  
  
          // 3. ASSERT
          assertThat(brb.getMinRating(), is(minRating));
      }
  
    // ...
  
  }
  </code></pre>
  
  <p>Which gets this Exception:</p>
  
  <pre><code>java.lang.ClassCastException: android.util.AttributeSet$MockitoMock$1142631110 cannot be cast to android.content.res.XmlBlock$Parser
  </code></pre>
  
  <p>I tried mocking TypeArray like <a href="https://medium.com/android-testing-daily/custom-view-attributes-ecf8822235a0" rel="noreferrer">this article</a> did, but my view treats the mocked context as null.</p>
  
  <p>Is there any good way to create a test case for custom view?</p>