测试开发

基于Monkey的iOS移动应用稳定性测试方案

LensNews
一、Ruby环境配置与安装
1、安装curl
     sudo apt-get install curl
2、通过curl命令安装rvm命令
       curl -L get.rvm.io | bash -s stable
     source ~/.bashrc
     source ~/.bash_profile
3、列出已知的Ruby版本
rvm list known
 # MRI Rubies
[ruby-]2.1.4
[ruby-]2.1[.5]
[ruby-]2.2[.1]
[ruby-]2.2-head
ruby-head
# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.1
4、通过rvm命令安装Ruby
wanghaifengdeiMac:~ $ rvm install 2.2.1
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.10/x86_64/ruby-2.2.1.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Installing requirements for osx.
Updating system................................................................-
5、检查已经安装的Ruby
wanghaifengdeiMac:~ $ rvm list
rvm rubies
=* ruby-2.2.1 [ x86_64 ]
# => - current
# =* - current && default
#  * - default
二、smart_monkey工具安装与配置
简要说明:
  1. 支持真机测试、模拟器测试
  2. 支持收集系统日志(Systemlog)、崩溃日志(Crashlog)、instrument行为日志
  3. 支持测试报告截图,绘制行为轨迹
  4. 支持测试设备信息收集
  5. 使用最新版的UIAutoMonkey,加入UI Holes与Application Not Repsonding ("ANR")的处理,添加custom.js作为入口脚本.
  6. 加入tuneup依赖
  7. 修改UIAutoMonkey.js中截图策略,为每个Event Action进行截图
  8. 支持测试执行过程中App进入后台,自动恢复(测试不会block)
1、安装好ruby之后,紧接着安装smart_monkey
wanghaifengdeiMac:~ $ gem install smart_monkey
Fetching: smart_monkey-0.5.0.gem (100%)
Successfully installed smart_monkey-0.5.0
Parsing documentation for smart_monkey-0.5.0
Installing ri documentation for smart_monkey-0.5.0
Done installing documentation for smart_monkey after 1 seconds
1 gem installed
2、检查smart_monkey是否安装成功
wanghaifengdeiMac:~ $ smart_monkey -h
  • -a: 指向被测程序的BundleID(不可缺省)。e.g.-a com.mytest.app
  • -w: 指向测试设备的UDID,可以通过$instruments -s devices进行设备id的查看,若缺省则默认指向第一台设备(模拟器或真机)。
  • e.g.-w 26701a3a5bc17038ca0465186407b912375b35a7
  • -n: monkey测试的执行次数,默认为1次。e.g.-n 3
  • -d: 测试报告地址,默认为当前目录下的smart_monkey_result文件夹下。e.g.-d ~/my-monkey-test-result
  • -t: 执行时间,单位为秒。e.g.-t 60
  • -s: 指向被测app的.dSYM文件,若出现crash,解析crash为明文。e.g.-s testapp.dSYM
  • -c: 自定义的配置集路径,参数必须为目录,目录下必须包含custom.js,若使用handler,目录下需存在名为handler的文件夹,用于存放相关文件。e.g.-c /my/path/custom_cfg
如果使用custom_cfg必须遵守如下目录结构:
  • --event-number: 定义Monkey测试的总事件数,默认为50。e.g.--event-number 100
  • --compress-result: 对测试过程中截取的图片进行压缩,以节省空间开销。e.g.--compress-result 50%
  • --detail-count: 定义报告详情中记录的事件总数,默认为50,即在报告当中展示最近的50次随机事件,且进行操作示意绘制。e.g.--detail-count 100
  • --show-config: 打印当前的配置信息,即custom.js。e.g.--show-config
  • --drop-useless-img: 删除除展示在报告当中的其余截图,以节省空间开销,如,一轮Monkey测试共产出截图100张,参数--detail-count设置为20,那么使用--drop-useless-img会删除其余80张截图。e.g.--drop-useless-img
  • --list-app: 打印当前连接的真机及模拟器中所安装的app。e.g.--list-app
  • --list-devices: 打印当前所有可用设备。e.g.--list-devices
  • --reset-ios-sim: 重启模拟器。e.g.--reset-ios-sim
  • --version: 打印smart_monkey的版本号。e.g.--version
4、检查当前已连接电脑的苹果手机设备
 其中:iPhone6p (9.2)为真机,其余为模拟器
wanghaifengdeiMac:~ $ instruments -s devices
Known Devices:
2015-12-24 13:42:57.871 instruments[53432:3770364] WebKit Threading Violation - initial use of WebKit from a secondary thread.
王海峰的iMac [DA5E585E-F33C-5665-BB3C-A094796B6E73]
iPhone6p (9.2) [a4ba1247eb17079858e6bd1cc8ae78360b06cf0b]
5、执行monkey 真机稳定性测试
wanghaifengdeiMac:~ $ smart_monkey -a com.yueapp.sns -w a4ba1247eb17079858e6bd1cc8ae78360b06cf0b -n 3 -t 500
INSTRUMENTS_TRACE_PATH : /Users/wanghaifeng/*.trace
RESULT_BASE_PATH : /Users/wanghaifeng/smart_monkey_result
{:app_path=>"com.yueniapp.sns", :device=>"a4ba1247eb17079858e6bd1cc8ae78360b06cf0b", :run_count=>3, :time_limit_sec=>500, :detail_event_count=>50}
2015-12-24 15:02:12.084 instruments[1073:10978] WebKit Threading Violation - initial use of WebKit from a secondary thread.
=================================== Start Test (1/3) =======================================
Attempting iOS device system log capture via deviceconsole.
BundleID was found: com.yueapp.sns
Run: ["instruments", "-w", "a4ba1247eb17079858e6bd1cc8ae78360b06cf0b", "-l", "500000", "-t", "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate", "com.yueniapp.sns", "-e", "UIASCRIPT", "/Users/wanghaifeng/smart_monkey_result/report_20151224150203/custom.js", "-e", "UIARESULTSPATH", "/Users/wanghaifeng/smart_monkey_result/report_20151224150203"]
2015-12-24 15:02:35.557 instruments[1140:11610] WebKit Threading Violation - initial use of WebKit from a secondary thread.
注意:iOS 模拟器是 x86 的 CPU,真机是 arm 的。因此大部分情况下一个 ipa 只能在模拟器或者真机上运行,否则就会闪退哦~
6、执行monkey模拟器稳定性测试
wanghaifeng$ smart_monkey -a com.yueniapp.sns -w C670A163-45CC-479A-987C-502F6A522D93 -n 3 -t 500
INSTRUMENTS_TRACE_PATH : /Users/wanghaifeng/*.trace
RESULT_BASE_PATH : /Users/wanghaifeng/smart_monkey_result
{:app_path=>"com.yueniapp.sns", :device=>"C670A163-45CC-479A-987C-502F6A522D93", :run_count=>1, :time_limit_sec=>nil, :detail_event_count=>50}
=================================== Start Test (1/1) =======================================
Attempting iOS device system log capture via deviceconsole.
BundleID was found: com.yueniapp.sns
Run: ["instruments", "-w", "C670A163-45CC-479A-987C-502F6A522D93", "-t", "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate", "com.yueniapp.sns", "-e", "UIASCRIPT", "/Users/wanghaifeng/smart_monkey_result/report_20151225104306/custom.js", "-e", "UIARESULTSPATH", "/Users/wanghaifeng/smart_monkey_result/report_20151225104306"]
2015-12-25 02:43:52 +0000 Debug: target.frontMostApp().alert().cancelButton().tap()
7、查看测试报告
测试报告默认放在 bin/smart_monkey_result中,具体位置在测试命令最后输出的信息中可以找到,
例如上面的例子中测试报告位置为:  Monkey Test Report:/Users/wanghaifeng/smart_monkey_result/report_20151225104306/index.html
三、发现问题以及解决方案
问题一:配置好环境变量后,输入samrt_monkey,提示如下错误
wanghaifengdeiMac:~ wanghaifeng$ smart_monkey
/Users/wanghaifeng/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- erubis (LoadError)
from /Users/wanghaifeng/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/wanghaifeng/Tools/CrashMonkey4IOS/lib/smart_monkey/monkey_runner.rb:7:in `<module:UIAutoMonkey>'
from /Users/wanghaifeng/Tools/CrashMonkey4IOS/lib/smart_monkey/monkey_runner.rb:3:in `<top (required)>'
from /Users/wanghaifeng/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/wanghaifeng/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/wanghaifeng/Tools/CrashMonkey4IOS/lib/smart_monkey.rb:3:in `<top (required)>'
from /Users/wanghaifeng/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/wanghaifeng/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
 from /Users/wanghaifeng/Tools/CrashMonkey4IOS/bin/smart_monkey:10:in `<main>'
解决方案:原因是没有安装erubis,然后gem install erubis即可
问题二:输入gem install samrt_monkey,提示找不到
wanghaifengdeiMac:~ $ gem install smart_monkey
ERROR:  Could not find a valid gem 'smart_monkey' (>= 0) in any repository
解决方案:原因是没有添加smart_monkey的源
$ gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
$ gem sources -l

(1)

本文由 小蜜蜂信息网 作者:admin 发表,转载请注明来源!

关键词:
LensNews

热评文章

发表评论