如何,看是否有子活动启动或不 [英] How to see if a sub-activity was started or not

查看:106
本文介绍了如何,看是否有子活动启动或不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个单元测试Android应用程序。

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);
}

我设置一个断点,看着都procInfos和流程,我无法看到子活动的名称。

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?

我不喜欢用任何其他框架,如Robotium,比什么在ADK提供的其他。

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

编辑:我不知道这是否是一个子活动毕竟。我刚刚看了一篇文章,说这被认为是一个子活动,如果它开始startActivityForResult()。点击按钮监听我与startActivity()启动它。

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().

推荐答案

您需要的活动监视器等待开始活动。
一个非常类似的例子是刊登在 Android应用程序测试指南

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

这篇关于如何,看是否有子活动启动或不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆