小编bmv*_*143的帖子

getActivity()调用导致RuntimeException:无法启动意图Intent act = android.intent.action.MAIN

更新了#1:更多信息添加到本文末尾

我是Android开发和测试的新手.

我有三个Espresso测试.第一次测试通过,但第二次测试不会运行,因为在第二次测试之前在setUp()方法中调用getActivity()总是失败:

Blockquote java.lang.RuntimeException:无法在45秒内启动意图Intent {act = android.intent.action.MAIN flg = 0x10000000 cmp = my.packagename/.ActivityMain}....

第三次测试通过.

我在创建时没有任何长时间运行的操作,动画或网络调用.我可以点击我的应用程序中的所有菜单项,手动重复测试流程而不会出现问题.

出于某种原因,第一次测试在第二次测试之前"中断"setUp()中的getActivity()调用.以下所有测试(第二次测试后)都将运行正常.

我发现了类似的问题,但看起来它没有解决,它有一点点不同的问题.

测试代码:

import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import net.humblegames.bodylasticscalculator.ActivityMain;
import net.humblegames.bodylasticscalculator.R;
import net.humblegames.bodylasticscalculator.applogic.BandSystem;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;

import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;

public class MenuNavigationTestExperiment extends …
Run Code Online (Sandbox Code Playgroud)

eclipse android runtimeexception android-espresso

13
推荐指数
1
解决办法
9174
查看次数

Handler.handleMessage在测试中未调用,但在应用程序中调用

我有一个在单独进程中运行的服务.该服务在onCreate()方法中生成一个新线程.该线程将消息发送回服务.

如果我手动启动应用程序一切正常 - Handler我的服务收到消息.但在我的测试handleMessage()方法中永远不会被调用.

如何修复测试以使handleMessage()方法有效?

谢谢!

服务:

public class MyService extends Service {

    private ServiceHandler mHandler;
    private final int MSG_HELLO_WORLD = 1;

    private final String TAG = getClass().getSimpleName();

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        return null;
    }


    @Override
    public void onCreate() {
        Log.d(TAG, "MyService.onCreate");
        super.onCreate();

        mHandler = new ServiceHandler();

        new Thread(new Runnable() {
            @Override
            public void run() {
                Log.d(TAG, "Thread: run()");

                while (true) { …
Run Code Online (Sandbox Code Playgroud)

java android android-service android-testing android-handler

3
推荐指数
1
解决办法
2833
查看次数

如何在Robotium测试中使用SeekBar模拟用户交互("fromUser = true")?

我的代码使用传递给onProgressChanged()方法的fromUser参数来区分用户和代码与SeekBar的交互:

        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean fromUser) {

            if (fromUser) {
                // execute only if it was user interaction with the SeekBar
                ...
            }
        }
Run Code Online (Sandbox Code Playgroud)

当我尝试使用robotium测试我的SeekBar时,我无法"模拟用户与SeekBar的交互":

 solo.setProgressBar(mSeekBar, newValue);
Run Code Online (Sandbox Code Playgroud)

使用fromUser == false执行onProgressChanged()回调.

是否有可能编写Robotium测试来设置SeekBar的进度并同时模拟用户交互(fromUser == true)?

谢谢!

android robotium

2
推荐指数
1
解决办法
1101
查看次数