Carlisle's Site

Back

注:文中提到的例子地址是 https://github.com/CarlisleChan/CIPractice

另外 android 的自动化测试框架很多,这里只介绍一些常用的。

UI Automation Framework#

  • UIAutomator
  • Espresso
  • Monkey

给出一个 Monkey 参考

adb shell monkey  -p com.tencent.mm -s 100 --throttle 10 --ignore-crashes --ignore-timeouts --monitor-native-crashes --pct-appswitch 30 --pct-majornav 20 --pct-nav 20 --pct-touch 20 --pct-motion 10 -v -v -v 100 > monkey_log.txt
shell

收集 crash 和 ANR 等错误一般的做法就是去 log 日志中搜索对应字段,其实可以使用脚本处理过滤,输出方便观察的日志,同时也可以做到统计次数等。

Unit Test Framework#

  • Robolectric
  • Powermock
  • Mockito
  • JUnit

其他专项指标测试#

1. 静态代码检查#

请参看例子中的配置,执行对应脚本即可。

  • checkstyle
  • lint
  • findbugs
  • pmd
  • infer

2. apk info#

dexcount#

在项目根目录的 build.gradle 中添加 classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.5.2'

在 app 项目的 build.gradle 中添加 apply plugin: 'com.getkeepsafe.dexcount',执行构建动作即可看到分析结果。

apk size#

在终端执行以下命令即可

mkdir -p app/build/outputs/apksize
OUTFILE=app/build/outputs/apksize/result.csv
echo filesize > $OUTFILE
# yep, that's for Mac. Use "stat -c %s" instead on Linux
stat -f %z app/build/outputs/apk/app-debug.apk >> $OUTFILE
shell

3. 内存泄漏检查#

4. 启动速度检测#

5. APK 包分析#

6. 安全扫描#

7. 代码覆盖率#

使用的是 jacoco

资源:#

google 官方测试库的使用 https://google.github.io/android-testing-support-library/

参考#

持续集成的探索之 Android
https://carlislechan.github.io/blog/20170215-ci-android
Author Carlisle
Published at February 14, 2017
Comment seems to stuck. Try to refresh?✨