monkey测试样例

时间:2024-11-22 13:33:56

我们通过在CMD窗口中执行: adb shell monkey {+命令参数}来进行Monkey测试了。首先,我们准备了一个有bug的项目CityWeather;通过测试这个项目(源码在附件文件夹中),我们来理解Monkey测试的步骤以及如何知道哪些应用程序能够用Monkey进行测试。Windows环境下(注:2—4步是为了查看我们可以测试哪些应用程序包,可省略):

1、通过eclipse启动Android项目WhoisSinger;

2、在命令行中输入:adb devices 查看设备连接情况,如下图所示:

3、在有设备连接的前提下,在命令行中输入:adb shell 进入shell界面

4、查看data文件夹下的应用程序包。注:我们能测试的应用程序包都在这个目录下面输入ls data;

5、以local作为对象进行MonkeyTest

#monkey -p local -v 500

其中-p表示对象包,local 表示你需要测试的包名, –v 表示反馈信息级别运行过程中,WhoisSinger工程在不断地切换画面。按照选定的不同级别的反馈信息,在Monkey中还可以看到其执行过程报告和生成的事件。

6、首先,我们创建monkey.txt文件,然后将测试结果导出到monkey.txt文件夹,

# monkey -p kedi songs -v 200 >monkey.txt

7、分析测试结果

//伪随机种子为1492145723765,事件总数为200

:Monkey: seed=1492145723765 count=200

:AllowPackage: com.kedi.songs//包名

:IncludeCategory: android.intent.category.LAUNCHER//包含的类别

:IncludeCategory: android.intent.category.MONKEY

//各种事件所占的比例

// Event percentages:

//   0: 15.0%

//   1: 10.0%

//   2: 2.0%

//   3: 15.0%

//   4: -0.0%

//   5: 25.0%

//   6: 15.0%

//   7: 2.0%

//   8: 2.0%

//   9: 1.0%

//   10: 13.0%

:Switch:

//表示跳转到com.kedi.songs里面的MainActivity这一个Activity里。

#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.kedi.songs/.MainActivity;end

//允许此Intent跳转   

// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.kedi.songs/.MainActivity } in package com.kedi.songs

//发送的一些动作,如点击按下,点击放开,移动

:Sending Touch (ACTION_DOWN): 0:(88.0,993.0)

:Sending Touch (ACTION_UP): 0:(105.03915,1001.184)

:Sending Trackball (ACTION_MOVE): 0:(4.0,3.0)

:Sending Touch (ACTION_DOWN): 0:(408.0,781.0)

:Sending Touch (ACTION_UP): 0:(415.41663,780.68005)

:Sending Touch (ACTION_DOWN): 0:(218.0,758.0)

:Sending Touch (ACTION_UP): 0:(215.02052,758.3537)

:Sending Touch (ACTION_DOWN): 0:(419.0,95.0)

:Sending Touch (ACTION_UP): 0:(413.2224,94.99081)

:Sending Touch (ACTION_DOWN): 0:(740.0,642.0)

:Sending Touch (ACTION_UP): 0:(659.1589,553.72363)

:Sending Touch (ACTION_DOWN): 0:(236.0,290.0)

:Sending Touch (ACTION_UP): 0:(246.88383,289.21118)

:Sending Touch (ACTION_DOWN): 0:(186.0,504.0)

:Sending Touch (ACTION_UP): 0:(192.02328,495.53183)

:Sending Touch (ACTION_DOWN): 0:(753.0,126.0)

:Sending Touch (ACTION_UP): 0:(768.0,67.10371)

:Sending Touch (ACTION_DOWN): 0:(633.0,298.0)

:Sending Touch (ACTION_UP): 0:(633.8099,293.15222)

:Sending Touch (ACTION_DOWN): 0:(49.0,899.0)

:Sending Touch (ACTION_UP): 0:(21.048468,958.5391)

:Sending Touch (ACTION_DOWN): 0:(111.0,219.0)

:Sending Touch (ACTION_UP): 0:(111.975845,239.48457)

:Sending Touch (ACTION_DOWN): 0:(626.0,1071.0)

:Sending Touch (ACTION_UP): 0:(610.2667,1112.3813)

:Sending Touch (ACTION_DOWN): 0:(165.0,817.0)

:Sending Touch (ACTION_UP): 0:(153.39474,810.34625)

:Sending Trackball (ACTION_MOVE): 0:(2.0,-2.0)

//[calendar_time:2017-03-29 01:51:38.685  system_uptime:755242]

// Sending event #100

//继续发送动作

:Sending Touch (ACTION_DOWN): 0:(32.0,71.0)

:Sending Touch (ACTION_UP): 0:(37.523315,75.30026)

:Sending Touch (ACTION_DOWN): 0:(442.0,421.0)

:Sending Touch (ACTION_UP): 0:(441.8704,413.11942)

:Sending Trackball (ACTION_MOVE): 0:(4.0,-3.0)

:Sending Trackball (ACTION_MOVE): 0:(-4.0,3.0)

:Sending Touch (ACTION_DOWN): 0:(745.0,204.0)

:Sending Touch (ACTION_UP): 0:(740.33636,202.39874)

:Sending Trackball (ACTION_MOVE): 0:(-3.0,-3.0)

:Sending Touch (ACTION_DOWN): 0:(325.0,402.0)

:Sending Touch (ACTION_UP): 0:(257.38608,525.6119)

:Sending Touch (ACTION_DOWN): 0:(442.0,139.0)

:Sending Touch (ACTION_UP): 0:(427.31436,146.27611)

:Sending Trackball (ACTION_MOVE): 0:(4.0,0.0)

:Sending Touch (ACTION_DOWN): 0:(552.0,491.0)

:Sending Touch (ACTION_UP): 0:(557.97705,487.98703)

:Sending Trackball (ACTION_MOVE): 0:(-1.0,-4.0)

//注入事件200

Events injected: 200

//发送屏幕翻转 度=0,存留=

:Sending rotation degree=0, persist=false

//丢弃的:键=0,指针=0,轨迹球=0,翻转=0。

:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0

//网络统计经过时间为9046ms(0ms是用在手机上的,9046ms是用于无线网络,没有连接的时间为0ms)。

## Network stats: elapsed time=9046ms (0ms mobile, 9046ms wifi, 0ms not connected)

//测试完成

// Monkey finished

从上述例子中可以看出,该程序在这次测试中没有什么问题,若程序出现问题终端将打印出异常供程序员查找错误。