adb shell am instrument 命令详解

adb指令启动测试脚本

adb shell am instrument -w com.netease.open.airbase/android.support.test.runner.AndroidJUnitRunner

1 Instrument是什么?

instrument为am命令的一个子命令。用于启动一个Instrumentation测试。首先连接手机或者模拟器,通过adb shell命令,进入shell层进行操作。

2 命令格式及参数解读(来自官网)

格式:instrument [options] component

目标 component 是表单 test_package/runner_class,在UiAutomator2.0中,目标 component为:测试包名/android.support.test.runner.AndroidJUnitRunner(即运行器固定:AndroidJUnitRunner类是一个JUnit测试运行器,允许运行JUnit 3或JUnit 4测试类在 Android 设备上,包括那些使用Espresso和UI Automator框架。)

各项参数:

-r:以原始形式输出测试结果;该选项通常是在性能测试时与[-e perf true]一起使用。
-e name value:提供了以键值对形式存在的过滤器和参数。例如:-e testFile (运行文件中指定的用例);-e package (运行这个包中的所有用例)…… 有十几种。
-p file:将分析数据写入 file。
-w:测试运行器需要使用此选项。-w <test_package_name>/<runner_class> :<test_package_name>和<runner_class>在测试工程的AndroidManifest.xml中查找,作用是保持adb shell打开直至测试完成。
–no-window-animation:运行时关闭窗口动画。
–user user_id | current:指定仪器在哪个用户中运行;如果未指定,则在当前用户中运行。
3 怎么运行手机中现有的instrumentation, 并输出详细结果,同时将profiling性能数据写到本地文件中?

先列出手机中已安装的instrumentation:adb shell pm list instrumentation
adb shell am instrument XXX
4 命令的具体使用,比如com.le.tcauto.uitest.test是包含所有测试代码的应用的包名:(来自:http://blog.csdn.net/swordgirl2011/article/details/50881390)

运行所有的用例: adb shell am instrument -w com.le.tcauto.uitest.test/android.support.test.runner.AndroidJUnitRunner
运行一个类中的所有用例:
adb shell am instrument -w -r -e class com.letv.leview.setproxy com.le.tcauto.uitest.test/android.support.test.runner.AndroidJUnitRunner

运行类中的某个方法:adb shell am instrument -w -r -e debug false -e class com.letv.leview.setproxy#testDemo com.le.tcauto.uitest.test/android.support.test.runner.AndroidJUnitRunner
运行多个类的所有用例:adb shell am instrument -w -r -e debug false -e class com.letv.leview.setproxy,com.letv.leview.resetdate com.le.tcauto.uitest.test/android.support.test.runner.AndroidJUnitRunner
运行所有测试用例除了指定的类:adb shell am instrument -w -r -e notClass com.letv.leview.setproxy com.le.tcauto.uitest.test/android.support.test.runner.AndroidJUnitRunner
运行所有测试除了指定的用例:adb shell am instrument -w -r -e debug false -e class com.letv.leview.setproxy#testDemo com.le.tcauto.uitest.test/android.support.test.runner.AndroidJUnitRunner
运行文件中的所列的用例:adb shell am instrument -w -e testFile /sdcard/tmp/testFile.txt com.android.foo/com.android.test.runner.AndroidJUnitRunner 文件制定的 格式为:com.android.foo.FooClaseName#testMethodName
运行指定测试切片的用例:adb shell am instrument -w -e numShards 4 -e shardIndex 1 com.android.foo/android.support.test.runner.AndroidJUnitRunner
运行指定注解的测试用例:adb shell am instrument -w -e annotation com.android.foo.MyAnnotation com.android.foo/android.support.test.runner.AndroidJUnitRunner。如果使用多个选项,则运行的用例为两者的交集,比如:“-e size large -e annotation com.android.foo.MyAnnotation”,将只运行同时含LargeTest和MyAnnotation注解的用例。
运行没有指定注解的用例:adb shell am instrument -w -e notAnnotation com.android.foo.MyAnnotation com.android.foo/android.support.test.runner.AndroidJUnitRunner,指定多个注解,用“,”隔开,e.g. adb shell am instrument -w -e notAnnotation com.android.foo.MyAnnotation,com.android.foo.AnotherAnnotation com.android.foo/android.support.test.runner.AndroidJUnitRunner
以上所有参数也可以通过标签配置在AndroidManifest文件,比如 ,通过shell命令 传入的参数将覆盖AndroidManifest文件中配置的参数。
5 开始容易写错?

AS ——Select Run/Debug —— Configuration ——Edit Configuration ——配置 ——OK

运行完成,下方会显示该命令,然后copy过来。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
android adb shell 命令大全 1. 显示系统中全部Android平台: android list targets 2. 显示系统中全部AVD(模拟器): android list avd 3. 创建AVD(模拟器): android create avd --name 名称 --target 平台编号 4. 启动模拟器: emulator -avd 名称 -sdcard ~/名称.img (-skin 1280x800) 5. 删除AVD(模拟器): android delete avd --name 名称 6. 创建SDCard: mksdcard 1024M ~/名称.img 7. AVD(模拟器)所在位置: Linux(~/.android/avd) Windows(C:\Documents and Settings\Administrator\.android\avd) 8. 启动DDMS: ddms 9. 显示当前运行的全部模拟器: adb devices 10. 对某一模拟器执行命令: abd -s 模拟器编号 命令 11. 安装应用程序: adb install -r 应用程序.apk 12. 获取模拟器中的文件: adb pull 13. 向模拟器中写文件: adb push 14. 进入模拟器的shell模式: adb shell 15. 启动SDK,文档,实例下载管理器: android 16. 缷载apk包: adb shell cd data/app rm apk包 exit adb uninstall apk包的主包名 adb install -r apk包 17. 查看adb命令帮助信息: adb help 18. 在命令行中查看LOG信息: adb logcat -s 标签名 19. adb shell后面跟的命令主要来自: 源码\system\core\toolbox目录和源码\frameworks\base\cmds目录。 20. 删除系统应用: adb remount (重新挂载系统分区,使系统分区重新可写)。 adb shell cd system/app rm *.apk 21. 获取管理员权限: adb root 22. 启动Activity: adb shell am start -n 包名/包名+类名(-n 类名,-a action,-d date,-m MIME-TYPE,-c category,-e 扩展数据,等)。 23、发布端口: 你可以设置任意的端口号,做为主机向模拟器或设备的请求端口。如: adb forward tcp:5555 tcp:8000 24、复制文件: 你可向一个设备或从一个设备中复制文件, 复制一个文件或目录到设备或模拟器上: adb push 如:adb push test.txt /tmp/test.txt 从设备或模拟器上复制一个文件或目录: adb pull 如:adb pull /addroid/lib/libwebcore.so . 25、搜索模拟器/设备的实例: 取得当前运行的模拟器/设备的实例的列表及每个实例的状态: adb devices 26、查看bug报告: adb bugreport 27、记录无线通讯日志: 一般来说,无线通讯的日志非常多,在运行时没必要去记录,但我们还是可以通过命令,设置记录: adb shell logcat -b radio 28、获取设备的ID和序列号: adb get-product adb get-serialno 29、访问数据库SQLite3 adb shell sqlite3 #cd system/sd/data //进入系统内指定文件夹 #ls //列表显示当前文件夹内容 #rm -r xxx //删除名字为xxx的文件夹及其里面的所有文件 #rm xxx //删除文件xxx #rmdir xxx //删除xxx的文件夹

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值