I am developing an Android app with several Activity classes. I am using Robolectric for unit testing. In the test setup I call onCreate(null) in the Activity being tested:
@Before
public void setUp() throws Exception {
activity = new StartARound();
activity.onCreate(null);
btnSelectCourse = (Button) activity.findViewById(com.catalyst.golfapp.R.id.btnSelectCourse);
btnAddACourse = (Button) activity.findViewById(com.catalyst.golfapp.R.id.btnAddACourse);
btnShowLocation = (Button) activity.findViewById(com.catalyst.golfapp.R.id.btnShowLocation);
textView1 = (TextView) activity.findViewById(com.catalyst.golfapp.R.id.textView1);
}
The problem is, the onCreate method for the Activity I'm testing calls:
getActionBar().setDisplayHomeAsUpEnabled(true);
Execution of this line of code produces a java.lang.NullPointerException error and the tests do not run. Any ideas, or additional code you'd like to examine?