android之instrumentation的简单记录

仪器测试

插桩测试提供了一种通过 am instrument 命令启动的特殊测试执行环境。

主要概念

  • 必须在应用软件包中声明插桩,方法是在应用软件包清单的 标记下嵌套 标记。
  • 每个 必须包含:
    第一: android:name 属性:它应该是测试应用中包含的 Instrumentation的子类的名称,该测试应用通常是正在使用的测试运行程序,例 如android.support.test.runner.AndroidJUnitRunner
    第二:必须定义 android:targetPackage 属性。其值应该设置为接受测试的应用软件包。

步骤总结

1.下面是框架服务封闭测试的常见位置:

frameworks/base/core/tests/coretests
frameworks/base/services/tests/servicestests

2.使用 m 命令构建测试模块

m FrameworksCoreTests
或者
make FrameworksCoreTests

3.安装生成的 APK

adb install -r ${OUT}/xxx/FrameworksCoreTests.apk

-w表示等待执行完成后才返回
-e表示带两个参数,将这两个参数作为键值对传递testRunner

1.apk 中的所有测试

adb shell am instrument -w com.android.frameworks.coretests\
  /android.support.test.runner.AndroidJUnitRunner

2.特定 Java 软件包下的所有测试

adb shell am instrument -w -e package android.animation \
  com.android.frameworks.coretests\
  /android.support.test.runner.AndroidJUnitRunner

3.特定类下的所有测试

adb shell am instrument -w -e class \
  android.animation.AnimatorSetEventsTest \
  com.android.frameworks.coretests\
  /android.support.test.runner.AndroidJUnitRunner

4.特定的测试方法

adb shell am instrument -w -e class \
  android.animation.AnimatorSetEventsTest#testCancel \
  com.android.frameworks.coretests\
  /android.support.test.runner.AndroidJUnitRunner

测试结果

 adb shell am instrument -w -e class   android.animation.AnimatorSetEventsTest#testCancel   com.android.frameworks.coretests  /android.support.test.runner.AndroidJUnitRunner

android.animation.AnimatorSetEventsTest:.

Time: 5.446

OK (1 test)

参考链接:https://source.android.google.cn/docs/core/tests/development/instrumentation?hl=zh-cn

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值