I am writing a test for my activity
MyActivity activity = new MyActivity();
activity.onCreate(null);
my activity expects and extra parameter开发者_StackOverflow社区s to be passed, so when I call onCreate it crashes. How can I pass an extra to my activity without using an Intent?
You could have the activity under test use some default values for the extra parameters, but I don't recommend that approach. Instead, just have the test pass in the values.
From http://developer.android.com/reference/android/test/ActivityInstrumentationTestCase2.html#setActivityIntent(android.content.Intent)
Call this method before the first call to getActivity() to inject a customized Intent into the Activity under test.
精彩评论