title: Testing TextView text colour using Robolectric for Android
body: <p>I'm trying to TDD/test the text colour of a textView for android. However all of the properties seem to return either 0 or null, does anyone know why?</p>
  
  <p>The code creating the text view:</p>
  
  <pre><code>public void setupTextView() {
  
      LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
      TextView textView = new TextView(this);
  
      textView.setText(job.getName());
  
      if (job.getLastBuild().getBuildStatus().equals("SUCCESS")) {
  
          textView.setTextColor(Color.parseColor("#007000"));
  
      } else {
  
         textView.setTextColor(Color.parseColor("#FF0000"));
  
      }
  
      layout.addView(textView);
  
  }
  </code></pre>
  
  <p>I've ran the application and the code above works.</p>
  
  <p>The properties I've tried accessing in the test code:</p>
  
  <pre><code>@Test
  public void firstTextViewShouldReflectPassingJobStatus() throws Exception {
  
      LinearLayout layout = layout = (LinearLayout) activity.findViewById(R.id.layout);
  
      TextView gomoTextView = (TextView) layout.getChildAt(0);
  
      System.out.println(gomoTextView.getCurrentTextColor()); //Returns 0
      System.out.println(gomoTextView.getTextColors()); //Returns null
      System.out.println(gomoTextView.getSolidColor()); //Returns 0
      System.out.println(gomoTextView.getCurrentHintTextColor()); //Returns 0
  
      //I also tried using `Robolectric.shadowOf()`:
      ShadowTextView shadowGomoTextView = Robolectric.shadowOf(gomoTextView);
  
      System.out.println(shadowGomoTextView.getTextColorHexValue()); //Returns 0
      System.out.println(shadowGomoTextView.getHintColorHexValue()); //Returns null
  
  }
  </code></pre>
  
  <p><strong>Update to answer comments</strong></p>
  
  <p>I have a before in the unit test class which calls <code>onCreate()</code>:</p>
  
  <pre><code>private LinearLayout layout;
  private HomeActivity activity;
  
  @Before
  public void setUp() throws Exception {
  
      activity = spy(new HomeActivity());
      Jenkins mockJenkins = TestUtilities.getTestJenkins();
      when(activity.getJenkins()).thenReturn(mockJenkins);
  
      activity.onCreate(null);
      layout = (LinearLayout) activity.findViewById(R.id.layout);
  
  }
  </code></pre>
  
  <p>And the the onCreate method in the HomeActivity class:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      Jenkins jenkins = getJenkins();
      displayJenkins(jenkins);
  }
  </code></pre>
  
  <p>And then display jenkins calls a load of other methods which include <code>setupTextView()</code></p>