为什么我的robotium测试用例在启动活动后没有立即启动?

时间:2012-09-20 07:28:52

标签: android robotium instrumentation

我为我的应用程序构建了一个Robotium测试用例。一切都很好,除了我需要手动与我的应用程序交互以使测试开始运行。这意味着我需要转到应用程序中的另一个活动,然后测试用例将开始。 出于某种原因,我的测试不会在启动时启动。

public class TestApk extends ActivityInstrumentationTestCase2{
private static final String TARGET_PACKAGE_ID= "com.bizzabo.client";
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.bizzabo.client.ui.activities.BzLauncher";
private static Class launcherActivityClass;
static{
    try
    {
        launcherActivityClass=Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
    } catch (ClassNotFoundException e){
        throw new RuntimeException(e);
    }}
public TestApk()throws ClassNotFoundException{
    super( launcherActivityClass);
}
private Solo solo;
@Override
protected void setUp() throws Exception
{
    solo = new Solo(getInstrumentation(),getActivity());

}

public void testInformationMenu() {
    final int INFORMATION_VIEW_NO = 11;

    solo.getCurrentActivity();
    solo.sleep(1000);
    solo.goBack();
    solo.sleep(1000);
    ArrayList<View> viewList = solo.getCurrentViews();
    solo.clickOnView(viewList.get(INFORMATION_VIEW_NO));
    solo.sleep(1000);
    solo.clickOnText("Add Event");
    solo.sleep(1000);
    solo.goBack();
    solo.clickOnView(viewList.get(INFORMATION_VIEW_NO));
    solo.clickOnText("Invite Your Friends");
    solo.sleep(1000);
    solo.goBack();
    solo.clickOnView(viewList.get(10));
    solo.sleep(1000);
    solo.enterText(0, "testbot");
    solo.sendKey(Solo.ENTER);
    solo.sleep(5000);
    solo.clickOnImage(2);
    solo.sleep(1000);
    solo.clickOnText("Join");
    solo.goBack();
    solo.clickOnText("Community");
    solo.sleep(1000);
    solo.clickOnText("Join");
    solo.goBack();
    solo.clickOnText("HERE NOW");
    solo.sleep(1000);
    solo.clickOnText("Check-In");
    solo.sleep(1000);
    solo.goBack();
    solo.clickOnText("Opportunities");
    solo.clickOnText("Messages");
    solo.clickOnText("Offers");
    solo.sleep(1000);
    solo.clickOnText("Event");
    solo.goBack();
    solo.sleep(1000);
    solo.clickOnText("Information");
    solo.clickOnText("Join");
    solo.goBack();
    solo.clickOnText("+ Invite");
    solo.goBack();
    solo.clickOnText("Buzz");
    solo.goBack();
    solo.goBack();
    solo.drag(400, 400, 400, 300, 1);
    solo.sleep(1000);
}

public void tearDown() throws Exception {
    solo.finishOpenedActivities();
}

}

3 个答案:

答案 0 :(得分:2)

我相信它应该像调用你的超类一样简单:

public void setUp() throws Exception {
    super.setUp();
    solo = new Solo(getInstrumentation(),getActivity());
}

public void tearDown() throws Exception {
    solo.finishOpenedActivities();
    super.tearDown();
}

这应该有助于设置所有内容,并且您的测试将正常运行,假设您的类名是正确的!

答案 1 :(得分:0)

在这一行,您可以编写测试开始的活动:

LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.bizzabo.client.ui.activities.BzLauncher";

检查您需要开始的正确活动。

答案 2 :(得分:0)

我的申请中遇到同样的问题。在我的活动上,我有一个显示gif动画的自定义视图(webview)。如果我从Activity中删除此视图,则测试将在启动时启动。但是如果该视图存在,则在我手动切换到下一个Activity之前,测试不会继续。