开发者

How to see if a sub-activity was started or not

I'm writing a unit test for an Android application.

I'd like to see if clicking a button will open a correct sub-activity or not.

There is a main activity, and within it, there are two buttons, each of which launches a sub activity when clicked.

I think the problem happens because these are sub-activities.

So, this is the test method in my unit test case.

@UiThreadTest
public void testActivityLaunch() {
    //Launches a subActivity
    theButton.performClick();

    ActivityManager am = (ActivityManager) mActivity.getSystemService(Service.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> procInfos 开发者_如何转开发= am.getRunningAppProcesses();
    List<ActivityManager.RecentTaskInfo> processes = am.getRecentTasks(5, ActivityManager.RECENT_WITH_EXCLUDED);
}

I set up a breakpoint and looked into both procInfos and processes, and I can't see the name of the subActivity.

I created a similar method in the app that is being tested, and I still couldn't see the name of the sub-activity in the list even after it was launched.

I just need an access to the name of sub-activity in the process list just to know if a button click has launched it properly or not. Is there any other way to test this?

I'd not like to use any other frameworks, such as Robotium, other than what's provided in ADK.

EDIT: I'm not sure if this is a sub-activity after all. I just read an article saying it is considered a sub-activity if it is started with startActivityForResult(). On the button click listener I'm starting it with startActivity().


You need an ActivityMonitor to wait for started Activities. A very similar example is featured in Android Application Testing Guide.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜