开发者

Testing an activity and pass an extra?

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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜