Android & Robotium - Test activity that expects an extra?

二次信任 提交于 2019-12-06 17:02:28

问题


It seems to me that robotium was designed in a way to test 1 Activity at a time instead of the whole application.

So my question is how do I test an activity that expects an extra to be passed to it? by extra I mean intent.putExtra("Something", object);


回答1:


The method setActivityIntent(Intent) should be what you are looking for. I used this method to provide a custom Intent to my Activity's TestCase. Just use it after you call super in your constructor.

Intent i = new Intent();
i.putExtra("myExtra", "anyValue");
setActivityIntent(i);

You don't have to do it in the constructor i think, but you need to make sure that you call it before you call getActivity() for the first time. getActivity will use your Intent to create the Activity.




回答2:


You could override getActivity() instead.

@Override
public NewActivity getActivity() {
    Intent intent = new Intent();
    intent.putExtra("exampleExtra", "some data");
    setActivityIntent(intent);
    return super.getActivity();
}

See Testing for Android with Robotium for more details.



来源:https://stackoverflow.com/questions/8335239/android-robotium-test-activity-that-expects-an-extra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!