开发者

Testing an activity and pass an extra?

开发者 https://www.devze.com 2023-03-08 12:29 出处:网络
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 on

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

精彩评论

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