title: How to mock Kotlin's kotlinx.android.synthetic views in Android
body: <p>I have a fragment written in Kotlin. I import layout views using </p>
  
  <pre><code>import kotlinx.android.synthetic.main.my_fragment_layout.
  </code></pre>
  
  <p>In one of my methods I am setting the TextView's text:</p>
  
  <pre><code>fun setViews() {
      myTextView.text = "Hello"
      // In Java I would have used:
      // (getView().findViewById(R.id.myTextView)).setText("Hello");
  }
  </code></pre>
  
  <p>In my plain JVM unit test, I want to test this method using Mockito.
  For example, if the above method was written in java I could do:</p>
  
  <pre><code>public void setViewsTest() {
      // Mock dependencies
      View view = Mockito.mock(View.class);
      TextView myTextView = Mockito.mock(TextView.class);
      when(fragment.getView()).thenReturn(view);
      when(view.findViewById(R.id. myTextView)).thenReturn(myTextView);
  
      // Call method
      fragment.setViews();
  
     // Verify the test
     verify(myTextView).setText("Hello");
  }
  </code></pre>
  
  <p>How can I do a similar implementation when using Kotlin's <code>kotlinx.android.synthetic</code> views?</p>