本文介绍了生命周期测试与Robotium:杀戮和重新启动活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何是否有可能重新启动,使用结束活动Robotium的 solo.goBack()

How is it possible to restart an activity that was ended using Robotium's solo.goBack()?

以下不重新启动的活动:(测试完成后确定)

The following does not restart the activity: (the test finishes ok)

    solo.goBack();
    try {
    //  recreate activity here
    runTestOnUiThread(new Runnable() {
        public void run() {
        getInstrumentation().callActivityOnCreate(getActivity(), 
                              null);
        getInstrumentation().callActivityOnStart(getActivity());
        getInstrumentation().callActivityOnResume(getActivity());
        }});
    }

你怎么重新启动,是由 Solo.goBack结束的活动()

  • 测试活动与robotium 流地址Robotium两项活动的变化,而不是destoying并重新启动。
  • Simulate Android的杀戮和重新启动服务与服务,而不是活动的交易(且没有答案)
  • Activity在不同的测试与Robotium不重新启动问如何手动重新启动该活动,但以不同的方式回答
  • Testing activity flow with robotiumaddresses changing between two activities in Robotium, not destoying and restarting.
  • Simulate Android killing and restart servicedeals with a service, not an activity (and is unanswered)
  • Activity doesn't restart in different tests with Robotiumasks how to restart the activity manually, but is answered in a different way

要重现一个最小的测试是这样,创建一个项目,其测试项目:

To reproduce a minimal test like this, create a project and its test project:

android create project -t 1 -p testRestart -k com.testRestart -a testactivity
cd testRestart
mkdir tests
cd tests
android create test-project -m .. -p .

复制 Robotium罐子测试/库文件夹。

package com.testRestart;

import android.test.ActivityInstrumentationTestCase2;
import com.robotium.solo.Solo;

public class testactivityTest extends ActivityInstrumentationTestCase2<testactivity> {
    private Solo solo;

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

    public testactivityTest() {
        super("com.testRestart", testactivity.class);

    }

    public void testDestroyAndRestart() {
        solo.goBack();
    try {
        //  recreate activity here
        runTestOnUiThread(new Runnable() {
            public void run() {
            getInstrumentation().callActivityOnCreate(getActivity(), 
                                  null);
            getInstrumentation().callActivityOnStart(getActivity());
            getInstrumentation().callActivityOnResume(getActivity());
            }});
    } catch ( Throwable t ) {
        throw new RuntimeException(t);
    }
    }
}

在测试文件夹中,做了

ant debug install
adb shell am instrument -w -e class com.testRestart.testactivityTest com.testRestart.tests/android.test.InstrumentationTestRunner

问题又来了:你怎么能重新启动,是由 Solo.goBack()结束活动

推荐答案

由于@IHeartAndroid在他的回答以this robotium问题(我还没有看到它之前,有通过@Flavio卡帕乔在注释为<一个链接href="http://stackoverflow.com/questions/13802233/how-to-restart-killed-android-application-in-testing-with-robotium?rq=1">related问题):

As @IHeartAndroid said in his answer to this robotium question (I had not seen it before, there was a link by @Flavio Capaccio in a comment to a "related question"):

launchActivity("com.testRestart", testactivity.class, null);

工作。这是 InstrumentationTestCase 的功能。

(如果你想upvote这个答案,upvote 他的回答为好)

(If you want to upvote this answer, upvote his answer as well)

这篇关于生命周期测试与Robotium:杀戮和重新启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 17:31