【问题标题】:failed to make test using uiautomator 2.0无法使用 uiautomator 2.0 进行测试
【发布时间】:2016-12-14 09:29:39
【问题描述】:

我想从命令行进行 uiautomator 2.0 测试。我的步骤如下:

  1. 创建一个 Instrumentation 项目,代码如下:

    package com.android.uiautomator.client;
    
    
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import android.app.Application;
    import android.app.Instrumentation;
    import android.content.Context;
    import android.support.test.InstrumentationRegistry;
    import android.support.test.runner.AndroidJUnit4;
    import android.test.ApplicationTestCase;
    
    @RunWith(AndroidJUnit4.class)
    public class Initialize {
    
    @Test
    public void testStartServer() {
        System.out.println("this is the test");
    }
    }
    
  2. 使用gradlew生成测试apk

  3. 将测试 apk 安装到安卓模拟器中

    adb shell push ${apkPath}/test.apk /data/local/tmp/com.android.test
    
    adb shell pm install -r /data/local/tmp/com.android.test
    
  4. 检查测试apk是否安装成功。我可以找到安装的apk。

    adb shell pm list packages
    
  5. 安装后,我在模拟器中检查了 Instrumentation,但我找不到关于测试 apk 的 Instrumentation。这将导致执行命令失败:

    adb shell am instrument -e class com.android.uiautomator.client.Initialize -w com.android.uiautomator.client.test/android.support.test.runner.AndroidJUnitRunner
    

所以,我很困惑。为什么我安装了测试 apk 后找不到仪器?

【问题讨论】:

    标签: android testing android-uiautomator


    【解决方案1】:

    你应该跑

    $ adb shell pm list instrumentation | grep 'target=applicationId'
    

    用您的 applicationId 替换 applicationId 以检查应用程序的可用检测。

    【讨论】:

    • 是的,我试过了。但我仍然找不到已安装的测试 apk 的工具
    • 那么,instrumentation 没有安装或者不适用于那个包,去掉 grep 过滤器并查看所有安装
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 2014-08-31
    • 2012-04-22
    • 1970-01-01
    相关资源
    最近更新 更多