title: Android data binding unit test : binding is null
body: <p>recently I worked on Android projects with data binding. When I try to create a fragment unit test, it says that the data binding is null.</p>
  
  <p>Here is the code exception trace :</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to read from field 'android.support.design.widget.TextInputLayout com.example.android.databinding.AFragmentBinding.textInputMortgagePrice' on a null object reference
  </code></pre>
  
  <p>Here's my unit test code snippet :</p>
  
  <pre><code>public void testIsInputValid() {
      assertTrue(mFragment.isInputValid());
  }
  </code></pre>
  
  <p>And here is my AFragment.java code snippet :</p>
  
  <pre><code>public class AFragment {
      private AFragmentBinding binding;
  
      @Override
      public boolean isInputValid() {
          resetError();
          return !isEmptyEditTextExist(); //A method to check if the text is empty
      }
  
      private void resetError() {
          binding.aTextInput.setError(null); //Here's where the error found
      }
  }
  </code></pre>
  
  <p>Here is my fragment.xml :</p>
  
  <pre><code>&lt;layout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      tools:context="AFragment"&gt;
  
  &lt;data&gt;
  
      &lt;variable
          name="vmA"
          type="path.to.viewmodel.class"/&gt;
  &lt;/data&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
              &lt;android.support.design.widget.TextInputLayout
                  android:id="@+id/a_text_input"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"&gt;
  
                  &lt;EditText
                      android:id="@+id/a_edit_text"
                      android:imeOptions="actionNext"
                      android:inputType="number"
                      android:maxLength="17"
                      android:text="@={vmA.price}"/&gt;
  
                  &lt;/android.support.design.widget.TextInputLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Does anybody know how to test a fragment / activity with data binding? Thanks for your help.</p>