Test code:
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class MainActivityTest {
private MainActivity mainActivity;
@Test
public void testMainActivity() {
MainActivity mainActivity = Robolectric.setupActivity(MainActivity.class);
mainActivity.findViewById(R.id.visual_button).performClick();
Intent expectedIntent = new Intent(mainActivity, VisualActivity.class);
ShadowActivity shadowActivity = Shadows.shadowOf(mainActivity);
Intent actualIntent = shadowActivity.getNextStartedActivity();
Assert.assertEquals(expectedIntent, actualIntent);
}
}
error reports:
java.lang.NullPointerException
my Robolectric version is 3.1.4... l have tried to find some solutions but failed. l'm sure that my test code are under src/test
, not src/androidTest
, can anybody help me ? Thanks in advance!