Android
2014.07.30 13:41

adb shell monkey - Monkey 사용하기

조회 수 27114 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print

몽키 테스트 (Monkey Test)


1) 몽키 테스트란?

   Monkey는 Android SDK에서 제공하는 프로그램으로, emulator나 device에 대해 random한 event stream을 발생시킵니다. 마치 원숭이가 기기를 작동하는 것처럼 random event를 발생시키기 때문에 monkey라는 이름이 붙여졌습니다. Event는 click, touch, gesture, system level event 등이 있습니다.

 

  

 

2) 몽키 테스트의 목적.

 

 Smart phone을 사용함에 있어, 인간은 선행 학습에 의해 device와 상호작용을 합니다.

 따라서 극단적인 사용이나 Edge case 들에 대해 Error 가 발생하는지를 확인하기가 어렵습니다.

 

Ex) Android phone에 OK 버튼을 포함한 Pop up 메뉴가 나오면 인간은 OK 버튼을 클릭하지만, 
      Monkey는 이를 인지하지 못하고 아무 버튼이나 누르거나 아무곳이나 터치하게 됩니다.

  

 Monkey 의 경우 random event stream을 발생시키기 때문에  예측불허인 극단적인 상황도 테스트가 가능(Stress-test)하며, 프로그램 자체에서 event 발생 빈도, event 발생 주기, event 발생 횟수 등을 조절할 수 있기 때문에 human resource를 낭비하지 않고도 극단적인 상황을 쉽게 테스트 할 수 있습니다. Monkey test는 보통 Application를 release 하기 전에 edge case들에 대한 저항성을 기르기 위해 합니다.
 
 
  
3) 몽키 테스트 사용 방법.
 
 3-1) 기본 사용
 
 
Monkey test는 adb shell 환경에서 작동하는 어플리케이션입니다.
따라서, environment path가 지정되어 있지 않다면, android-sdk-windows\tools 에서
실행해야 합니다.
 
기본명령어 : adb shell monkey <count>
    ex) adb shell monkey 500 -> 500개의 random event를 생성합니다.
 
기본명령어 #2 : adb ?s <device 명> shell monkey <count>
                      adb ?s emulator-<emulator number> shell monkey <count>
 
 
 
 3-2) 옵션 #1
 
Event 발생 percentage 조절
 
--pct-touch <percent>           Touch event 발생 빈도 조절
--pct-motion <percent>          드래그 event 발생 빈도 조절
--pct-trackball <percent>       트랙볼 event 발생 빈도 조절
--pct-nav <percent>              Navigation event 발생 빈도 조절
--pct-majornav <percent>      Back, Home 버튼등의 major navigation event 발생 빈도 조절
--pct-syskeys <percent>       System event 발생 빈도 조절 (Volume, home, end call 등)
--pct-appswitch <percent>    새로운 app. 실행 event 발생 빈도 조절
--pct-anyevent <percent>      기타 event 발생 빈도 조절
  
Ex) ..tools> adb shell monkey --pct-trackball 0 --pct-nav 0 --pct-touch 60 --pct-motion 20 ?v 500
                   : trackball, navigation 0%, touch 60%, motion 20%의 이벤트 비율로 event 500개 발생
 
 
 
  3-3) 옵션 #2
 
Seed & Throttle & Times
 
-s <seed>                      Seed 설정
 (Seed를 설정하지 않거나, 동일한 seed로 event를 발생시키면 항상 같은 event를 발생합니다.)
--throttle <milliseconds>   Event 사이의 delay 조정
-v <number of events>      설정한 수만큼의 event 발생
  
 Ex) ..tools> adb shell monkey ?s 1234 --throttle 1000 ?v 500
            : 1234를 seed로 1초(1000msec)마다, 총 500개의 event를 발생시킴
 
  
Tip) ?v 가 가장 마지막에 와야 나머지 option들이 제대로 적용됩니다.
 
 
  
  3-4) 옵션 #3
 
Package 설정 및 기타
 
-p <allowed-package name>   지정해준 Package에 포함된 activity들에 한정하여 test 한다.
 
Ex) ..tools> adb shell monkey -p com.lge.email -v 200
                   : email application에 대해 200회의 event 발생
 
 
Tip) Monkey test package는 화면에 보여지는 activity가 있는 것만 가능합니다.
     ex) com.google.email (O)   com.google.service.weatherwidget (X)







ADB 셸에서 Exerciser/Monkey 도구를 이용해서 특정 응용프로그램에 무작위한 사용자 사건들을 보낼 수 있다. 
Monkey라는 이름은 이 도구가 마치 단말기를 원숭이에게 넘겨준 후 마음대로 키를 누르거나 화면을 만지게 할 때와 비슷한 효과를 내기 때문에 붙은 것이다. 튼튼하게 설계되지 않았다면, 그런 무작위한 입력 사건들에 의해 응용프로그램이 죽게 될 것이다. 그런 일이 생기면 Monkey 도구는 무작위 입력을 중단하고 오류를 보고한다.
이런 기능은 품질 보증 작업에 아주 유용하다.

응용프로그램에 대해 Monkey 실행

monkey의 명령 구문은 다음과 같다.
    adb shell monkey -p <package> <options> <event count>
다음은 에뮬레이터에 있는 GroceryList 응용프로그램에 다섯 개의 무작위 사건을 보내는 예이다.
    adb -s emulator-5554 shell
    # monkey -p com.androidbook.grocerylist 5

Monkey의 행동보기

-v 옵션을 주면 Monkey가 발생하는 사건들을 볼 수 있다. 예를 들어 Monkey가 GroceryList 응용 프로그램에게 무작위 사건 다섯 개를 보내게 하되 그 사건들이 구체적으로 어떤 것인지를 알고 싶다면 다음과 같이 하면 된다.

adb -s emulator-5554 shell
#monkey -p com.androidbook.grocerylist -v  5

위의 명령어를 치면 테스팅한 리스트 내용이 찍혀 나온다.

Monkey의 행동 제어하기

사건 종류에 가중치를 부여함으로써 Monkey가 특정 종류의 사건들을 더/덜 발생하게 만들 수 있다. Monkey가 발생하는 사건 종류와 기본 백분율이 표에 정리 되어 있다.

<안드로이드 프로그래밍 부록 C p610 표 C.1 참고>

예) monkey -p com.androidbook.grocerylist --pct-nav 50 --pct-majornav 50 -v 5
     ( 기본 내비게이션과 주 내비게이션 사건들이 50 대 50 의 비율로 발생하게 하는 예이다. )

재현 가능한 무작위 사건 발생

무작위 사건 발생을 위해 Monkey 가 사용하는 난수열의 종잣값(seed)을 명시적으로 지정할 수 있다.
이 기능을 이용하면, 무작위한 사건들을 발생하되 필요하다면 나중에 그 사건들을 똑같이 다시 재현 하는 것이 가능하다 ( 이를 테면 버그가 제대로 고쳐졌는지를 확인하는 데 활용할 수 있다.)
종잣값을 지정하는 옵션은 -s이다.
  monkey -p <패키지> -s <종잣값> -v <사건 개수>
다음은 555라는 종잣값에 비롯된 다섯 무작위 사건들을 GroceryList에 보내는 예이다,.
  monkey - p com.androidbook.grocerylist -s 555 -v 5
종잣값이 다르면 Monkey가 발생하는 사건들도 달라진다. 반대로, 같은 종잣값을 지정하면 항상 동일한 사건들이 발생한다. 이는, 사건들을 재현하기 위해서는 종잣값을 기억해 둘 필요가 있다는 뜻이다. 한가지 방법은, 미리 무작위한 종잣값들을 만들어 두고, 그 종잣값을 (또한 종류별 발생 비율 등 기타 옵션들도)버그 보고서나 디버그 로그에 기록해 두는 것이다. 이후 버그 교정을 확인할 때 그 종잣값을 다시 지정함으로써 오작동을 일으킨 사건들을 재현 할 수 있다.

사건 발생 속도 제어

기본적으로 Monkey는 사건들을 최대한 빠르게 발생한다. 발생 속도를 변경하고 싶다면 다음과 같이  --throttle 옵션을 사용하면 된다:
   monkey --throttle <밀리 초 단위 시간> <사건 개수>
다음은 다섯 개의 무작위 사건을 1초(1000밀리초) 간격으로 GroceryList 응용프로그램에 보내는 예이다.
   monkey -p com.androidbook.grocerylist -v --throttle 1000 5





http://developer.android.com/tools/help/monkey.html



UI/Application Exerciser Monkey

The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.

Overview


The Monkey is a command-line tool that that you can run on any emulator instance or on a device. It sends a pseudo-random stream of user events into the system, which acts as a stress test on the application software you are developing.

The Monkey includes a number of options, but they break down into four primary categories:

  • Basic configuration options, such as setting the number of events to attempt.
  • Operational constraints, such as restricting the test to a single package.
  • Event types and frequencies.
  • Debugging options.

When the Monkey runs, it generates events and sends them to the system. It also watches the system under test and looks for three conditions, which it treats specially:

  • If you have constrained the Monkey to run in one or more specific packages, it watches for attempts to navigate to any other packages, and blocks them.
  • If your application crashes or receives any sort of unhandled exception, the Monkey will stop and report the error.
  • If your application generates an application not responding error, the Monkey will stop and report the error.

Depending on the verbosity level you have selected, you will also see reports on the progress of the Monkey and the events being generated.

Basic Use of the Monkey


You can launch the Monkey using a command line on your development machine or from a script. Because the Monkey runs in the emulator/device environment, you must launch it from a shell in that environment. You can do this by prefacing adb shell to each command, or by entering the shell and entering Monkey commands directly.

The basic syntax is:

$ adb shell monkey [options] <event-count>

With no options specified, the Monkey will launch in a quiet (non-verbose) mode, and will send events to any (and all) packages installed on your target. Here is a more typical command line, which will launch your application and send 500 pseudo-random events to it:

$ adb shell monkey -p your.package.name -v 500

Command Options Reference


The table below lists all options you can include on the Monkey command line.

CategoryOptionDescription
General--helpPrints a simple usage guide.
-vEach -v on the command line will increment the verbosity level. Level 0 (the default) provides little information beyond startup notification, test completion, and final results. Level 1 provides more details about the test as it runs, such as individual events being sent to your activities. Level 2 provides more detailed setup information such as activities selected or not selected for testing.
Events-s <seed>Seed value for pseudo-random number generator. If you re-run the Monkey with the same seed value, it will generate the same sequence of events.
--throttle <milliseconds>Inserts a fixed delay between events. You can use this option to slow down the Monkey. If not specified, there is no delay and the events are generated as rapidly as possible.
--pct-touch <percent>Adjust percentage of touch events. (Touch events are a down-up event in a single place on the screen.)
--pct-motion <percent>Adjust percentage of motion events. (Motion events consist of a down event somewhere on the screen, a series of pseudo-random movements, and an up event.)
--pct-trackball <percent>Adjust percentage of trackball events. (Trackball events consist of one or more random movements, sometimes followed by a click.)
--pct-nav <percent>Adjust percentage of "basic" navigation events. (Navigation events consist of up/down/left/right, as input from a directional input device.)
--pct-majornav <percent>Adjust percentage of "major" navigation events. (These are navigation events that will typically cause actions within your UI, such as the center button in a 5-way pad, the back key, or the menu key.)
--pct-syskeys <percent>Adjust percentage of "system" key events. (These are keys that are generally reserved for use by the system, such as Home, Back, Start Call, End Call, or Volume controls.)
--pct-appswitch <percent>Adjust percentage of activity launches. At random intervals, the Monkey will issue a startActivity() call, as a way of maximizing coverage of all activities within your package.
--pct-anyevent <percent>Adjust percentage of other types of events. This is a catch-all for all other types of events such as keypresses, other less-used buttons on the device, and so forth.
Constraints-p <allowed-package-name>If you specify one or more packages this way, the Monkey will only allow the system to visit activities within those packages. If your application requires access to activities in other packages (e.g. to select a contact) you'll need to specify those packages as well. If you don't specify any packages, the Monkey will allow the system to launch activities in all packages. To specify multiple packages, use the -p option multiple times ? one -p option per package.
-c <main-category>If you specify one or more categories this way, the Monkey will only allow the system to visit activities that are listed with one of the specified categories. If you don't specify any categories, the Monkey will select activities listed with the category Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY. To specify multiple categories, use the -c option multiple times ? one -c option per category.
Debugging--dbg-no-eventsWhen specified, the Monkey will perform the initial launch into a test activity, but will not generate any further events. For best results, combine with -v, one or more package constraints, and a non-zero throttle to keep the Monkey running for 30 seconds or more. This provides an environment in which you can monitor package transitions invoked by your application.
--hprofIf set, this option will generate profiling reports immediately before and after the Monkey event sequence. This will generate large (~5Mb) files in data/misc, so use with care. See Traceview for more information on trace files.
--ignore-crashesNormally, the Monkey will stop when the application crashes or experiences any type of unhandled exception. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.
--ignore-timeoutsNormally, the Monkey will stop when the application experiences any type of timeout error such as a "Application Not Responding" dialog. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.
--ignore-security-exceptionsNormally, the Monkey will stop when the application experiences any type of permissions error, for example if it attempts to launch an activity that requires certain permissions. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.
--kill-process-after-errorNormally, when the Monkey stops due to an error, the application that failed will be left running. When this option is set, it will signal the system to stop the process in which the error occurred. Note, under a normal (successful) completion, the launched process(es) are not stopped, and the device is simply left in the last state after the final event.
--monitor-native-crashesWatches for and reports crashes occurring in the Android system native code. If --kill-process-after-error is set, the system will stop.
--wait-dbgStops the Monkey from executing until a debugger is attached to it.



Dreamy의 코드 스크랩

내가 모으고 내가 보는

List of Articles
번호 분류 제목 날짜 조회 수 추천 수
506 LINUX awk 명령어 사용법 1 2006.02.16 114619 15
505 MFC CString 에서 형변환 함수들 총정리 2010.11.29 102706 0
504 Android adb am 명령어 ; app 실행 및 Intent 전송 2013.08.12 100254 0
503 Android [GIT 사용법] Git Tutorial 2011.12.26 96464 0
502 일반 ┗ bat(배치)파일 문법 2007.08.06 93472 8
501 LINUX [Shell Script] 리눅스 쉘(Shell) 스크립트 2014.09.23 86754 0
500 JAVA JAVA String 클래스 메소드 정리 1 2015.02.05 84930 0
499 LINUX [Shell Script] 쉘 스크립트에서의 사칙연산과 문자열 자르기 2014.11.01 81739 0
498 C# StringBuilder로 문자열 처리를 빠르게 2012.12.04 77937 0
497 LINUX du 명령어 사용법(디스크 용량 확인) 1 2012.05.31 77437 0
496 Python BeautifulSoup으로 웹에 있는 데이터 긁어오기 2013.04.08 76921 0
495 Android [GIT 사용법] 초보자가 알아두면 좋을 명령어 정리 1 2011.12.26 66476 0
494 LINUX errno.h - system error numbers 2013.01.09 65811 0
493 MFC API를 이용하는 유니코드와 ANSI 문자열간의 변환 방법 2006.04.14 63087 0
492 일반 findstr 사용법 - window용 find, grep 명령 2014.02.04 63074 0
목록
Board Pagination ‹ Prev 1 2 3 4 5 6 7 8 9 10 ... 34 Next ›
/ 34

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Designed by sketchbooks.co.kr / sketchbook5 board skin

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5