过程如下:
1、下载米聊 APK,重新签名,安装到模拟器。
2、简历测试工程导入 robotium jar 包。
3、清单文件如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xiaomi.channel.test"
    android:versionCode="1"
    android:versionName="1.0" >
    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.xiaomi.channel" />
    <uses-sdk android:minSdkVersion="8"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="android.test.runner" />
    </application>
</manifest>

4、用例代码如下:

public Solo solo;
    public Activity activity;
    private static Class<?> launchActivityClass;
    // 对应re-sign.jar生成出来的信息框里的两个值
    private static String mainActiviy = "com.xiaomi.channel.ui.ChannelLauncherActivity";
    private static String packageName = "com.xiaomi.channel";

    static {
        try {
            Log.v("LoginTest","start============");
            launchActivityClass = Class.forName(mainActiviy);
            Log.v("LoginTest","end============");
        } catch (ClassNotFoundException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    @SuppressWarnings("unchecked")
    public LoginTest() {
        super(launchActivityClass);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        Log.v("LoginTest","setUp============");
        this.activity = this.getActivity();
        this.solo = new Solo(getInstrumentation());
    }

    //米聊登陆 正确的用户名和密码
    public void testLoginWithIncorrentUsernameAndPassword(){
//      //一定时间以内等待text出现,否则出错 单位 毫秒
        solo.waitForText("Log In", 1, 10000);
//      点击text “Log In”
        solo.clickOnText("Log In");
        //一定时间以内等待text出现,否则出错 单位
        solo.waitForText("OK",1,2000);
        //输入text
        solo.enterText(0, "1234555");
        solo.enterText(1, "123");
        solo.clickOnText("OK");

        solo.waitForText("Incorrect ID number or password.", 1, 10000);
        assertTrue(solo.searchText("Incorrect ID number or password.", true));
    }   

    @Override
    protected void tearDown() throws Exception {
            this.solo.finishOpenedActivities();
    }

5、执行测试,console 端报错如下:

[2015-05-29 13:32:31 - MiTalkAPKDemoTest] ------------------------------
[2015-05-29 13:32:31 - MiTalkAPKDemoTest] Android Launch!
[2015-05-29 13:32:31 - MiTalkAPKDemoTest] adb is running normally.
[2015-05-29 13:32:31 - MiTalkAPKDemoTest] Performing android.test.InstrumentationTestRunner JUnit launch
[2015-05-29 13:32:31 - MiTalkAPKDemoTest] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'phone16'
[2015-05-29 13:32:35 - MiTalkAPKDemoTest] Application already deployed. No need to reinstall.
[2015-05-29 13:32:35 - MiTalkAPKDemoTest] Launching instrumentation android.test.InstrumentationTestRunner on emulator-5554
[2015-05-29 13:35:45 - MiTalkAPKDemoTest] Test run failed: Instrumentation run failed due to 'Process crashed.'
[2015-05-29 13:36:18 - WeixinAPKTest] Test run finished

6、logcat 信息

05-29 05:32:39.449: E/Trace(11495): error opening trace file: No such file or directory (2)
05-29 05:35:05.688: E/Trace(11508): error opening trace file: No such file or directory (2)
05-29 05:35:17.048: E/media_sdk(11508): CPU family is ARM
05-29 05:35:17.079: E/media_sdk(11508): Supported ARM features:
05-29 05:35:17.079: E/media_sdk(11508):   ARMv7
05-29 05:35:17.079: E/media_sdk(11508):   VFPv3
05-29 05:35:17.079: E/media_sdk(11508):   NEON
05-29 05:35:17.079: E/media_sdk(11508): CPU family is ARM
05-29 05:35:17.079: E/media_sdk(11508): Supported ARM features:
05-29 05:35:17.079: E/media_sdk(11508):   ARMv7
05-29 05:35:17.089: E/media_sdk(11508):   VFPv3
05-29 05:35:17.089: E/media_sdk(11508):   NEON
05-29 05:35:17.089: E/media_sdk(11508): CPU family is ARM
05-29 05:35:17.089: E/media_sdk(11508): Supported ARM features:
05-29 05:35:17.138: E/media_sdk(11508):   ARMv7
05-29 05:35:17.138: E/media_sdk(11508):   VFPv3
05-29 05:35:17.138: E/media_sdk(11508):   NEON
05-29 05:35:17.149: E/media_sdk(11508): CPU family is ARM
05-29 05:35:17.149: E/media_sdk(11508): Supported ARM features:
05-29 05:35:17.149: E/media_sdk(11508):   ARMv7
05-29 05:35:17.149: E/media_sdk(11508):   VFPv3
05-29 05:35:17.159: E/media_sdk(11508):   NEON
05-29 05:35:44.848: E/ActivityManager(163): ANR in com.xiaomi.channel
05-29 05:35:44.848: E/ActivityManager(163): Reason: Executing service com.xiaomi.channel/.service.PacketHandlerService
05-29 05:35:44.848: E/ActivityManager(163): Load: 4.13 / 1.99 / 1.06
05-29 05:35:44.848: E/ActivityManager(163): CPU usage from 0ms to 8901ms later:
05-29 05:35:44.848: E/ActivityManager(163):   36% 11495/com.xiaomi.channel: 33% user + 2.7% kernel / faults: 2088 minor
05-29 05:35:44.848: E/ActivityManager(163):   33% 11456/com.tencent.mm: 32% user + 1.3% kernel / faults: 2056 minor
05-29 05:35:44.848: E/ActivityManager(163):   24% 163/system_server: 20% user + 4.5% kernel / faults: 263 minor
05-29 05:35:44.848: E/ActivityManager(163):   2.2% 45/adbd: 0.2% user + 2% kernel

7、在真机上测试都 ok,在模拟器上就 crash,下载了微信 apk 测试后也是同样情况;被测程序有源代码也能正常跑。
8、由于本人比较固执,想弄明白为什么在模拟器上会 crash,不想不了了之。
8、出问题后在网上搜了各种解决办法都不行,恳请大家帮忙分析分析,万分感谢!!


↙↙↙阅读原文可查看相关链接,并与作者交流