Android测试方法论

背景:

使用自动化测试脚本对性能测试相当关键,对于检测内存泄漏等性能问题帮助很大

现状:

目前了解到客户端使用的自动化测试脚本分如下两类,针对不同场景的测试可以添加自己的方法然后执行就可以了

  • 使用google提供的androidTest自动化测试,需要找到对应需要操作的控件id
  • 连接手机后使用android studio打开项目工程代码
  • 后可以看到如下,点击下图类似小三角即可运行测试用例
  • androidTest作为官方推荐方式,可以比较好的兼容android studio内的profiler等监测工具,这是一个极大的优势,使用其余外部内存工具或者自动化测试工具或多或少会占用adb连接,导致profiler断开等问题。
    • Android测试方法论_第1张图片
       
  • 使用shell脚本+adb工具执行一些屏幕点击和长按等事件,通过屏幕上的操作热区来定位操作
    • 相对于第一种方法,这种方法可以对代码无感知,比较方便,但是windows需要使用mingw32之类的工具执行shell
    • 脚本文件类似这种
    • #!/bin/bash
      
      device=$1
      
      x=`adb -s $device shell dumpsys window displays|grep init|awk '{print $3}'|awk -F "=" '{print $2}'|awk -F "x" '{print $1}'`
      y=`adb -s $device shell dumpsys window displays|grep init|awk '{print $3}'|awk -F "=" '{print $2}'|awk -F "x" '{print $2}'`
      
      echo $x $y
      
      i=1080
      j=1920
      
      a="549 / $i"
      b="1838 / $j"
      home_play="`expr $x \* $a`  `expr $y \* $b`"
      record="`expr $x \* 537 / $i`  `expr $y \* 1651 / $j`"
      sticker="`expr $x \* 96 / $i`  `expr $y \* 964 / $j`"
      random="`expr $x \* 533 / $i`  `expr $y \* 691 / $j`"
      record_finish="`expr $x \* 958 / $i`  `expr $y \* 1638 / $j`"
      effectmix="`expr $x \* 464 / $i`  `expr $y \* 1764 / $j`"
      selun="`expr $x \* 586 / $i`  `expr $y \* 1572 / $j`"
      bendi="`expr $x \* 774 / $i`  `expr $y \* 1581 / $j`"
      relang="`expr $x \* 377 / $i`  `expr $y \* 1572 / $j`"
      sanbai="`expr $x \* 1030 / $i`  `expr $y \* 1572 / $j`"
      effect_finish="`expr $x \* 1002 / $i`  `expr $y \* 1860 / $j`"
      edit_finish="`expr $x \* 913 / $i`  `expr $y \* 1788 / $j`"
      save="`expr $x \* 825 / $i`  `expr $y \* 1226 / $j`"
      gongkai="`expr $x \* 936 / $i`  `expr $y \* 895 / $j`"
      simi="`expr $x \* 691 / $i`  `expr $y \* 519 / $j`"
      draft="`expr $x \* 221 / $i`  `expr $y \* 1800 / $j`"
      push="`expr $x \* 719 / $i`  `expr $y \* 1812 / $j`"
      
      
      for ((i=0;i<30;i++))
      do
      	echo $i
      	adb -s $device shell input tap $home_play
      	sleep 6
      	adb -s $device shell input tap $sticker
      	sleep 2
      	adb -s $device shell input tap $random
      	sleep 10
      	adb -s $device shell input tap $record
      	sleep 20
      	adb -s $device shell input tap $effectmix
      	sleep 2
      	adb -s $device shell input swipe $selun $selun 4000
      	sleep 1
      	adb -s $device shell input swipe $bendi $bendi 4000
      	sleep 1
      	adb -s $device shell input swipe $relang $relang 4000
      	sleep 1
      	adb -s $device shell input swipe $sanbai $sanbai 4000
      	sleep 1
      	adb -s $device shell input tap $effect_finish
      	sleep 2
      	adb -s $device shell input tap $edit_finish
      	sleep 2
      	adb -s $device shell input tap $save
      	sleep 1
      	adb -s $device shell input tap $gongkai
      	sleep 2
      	adb -s $device shell input tap $simi
      	sleep 2
      	adb -s $device shell input tap $push
      	sleep 60
      done
      
      Android测试方法论_第2张图片

你可能感兴趣的:(android)