AndroidMonkey is an Android Library. It is, in fact, a copy of the original Android Monkey Tool and made as a library for testing and analysis (e.g. code coverage) purposes.

Tester/User can easily use the library to create random test cases to test android apps with GUI.

Why this library:

You can use this library to create random test cases for your application, with just few lines of code

You can add your assertions to access the state of the SUT (you can hardly do this with the Android Monkey Tool)

You can do Coverage analysis of random testing on Android Application, this is useful for Research Purpose (like what I'm doing)


우선, 위 open project에서 다운받은 example code를 ant로 빌드환경에 맞게 update를 해야한다.

이러한 작업을 완료한 3개의 파일을 본 블로그에 첨부한다.

1) monkey testing할 project를 target smartphone에 설치 한다.

명령어: ant emma debug install 

root@ubuntu:~/Android_Application_source/testingProjectPackage/NotePad# ant emma debug install

Buildfile: /root/Android_Application_source/testingProjectPackage/NotePad/build.xml





 [checkenv] Android SDK Tools Revision 22.2.1

 [checkenv] Installed at /root/Android_Application_tools/android-sdk-linux_r22


     [echo] Installing /root/Android_Application_source/testingProjectPackage/NotePad/bin/AntNotePad-debug.apk onto default emulator or device...

     [exec] 554 KB/s (63571 bytes in 0.112s)

     [exec] pkg: /data/local/tmp/AntNotePad-debug.apk

     [exec] Success


Total time: 6 seconds

2) app test project를 설치한다.

해당 project는 AndroidMonkey project와 종속성이 있다. 왜냐하면, 테스팅 수행 과정에서 random event를 생성해서 testing을 수행하기 때문이다.

root@ubuntu:~/Android_Application_source/testingProjectPackage/NotePadMonkeyTester# ant emma debug install

Buildfile: /root/Android_Application_source/testingProjectPackage/NotePadMonkeyTester/build.xml





 [checkenv] Android SDK Tools Revision 22.2.1

 [checkenv] Installed at /root/Android_Application_tools/android-sdk-linux_r22


Total time: 20 seconds

3) 테스팅을 실행한다.

환경은 notepad 어플리케이션에 2개의 post를 등록한 상태에서 실행을 한다.

명령어: adb shell am instrument -e coverage true -w

특이사항: 위 명령어를 실행하면 app project의 bin 디렉터리에 coverage.em 파일이 생성 되어 진다.

root@ubuntu:~/Android_Application_source/testingProjectPackage/NotePadMonkeyTester# adb shell am instrument -e coverage true -w

Test results for InstrumentationTestRunner=.

Time: 49.75

OK (1 test)

Generated code coverage data to /data/data/

3) report 생성.

주의: coverage.em이 없을 경우, app project 디렉터리에서 ant instrument 명령어를 실행해서 

root@ubuntu:~/Android_Application_source/testingProjectPackage/NotePad# adb pull /data/data/ .

17 KB/s (691 bytes in 0.039s)

root@ubuntu:~/Android_Application_source/testingProjectPackage/NotePad/bin# java -cp ~/Android_Application_tools/android-sdk-linux/tools/lib/emma.jar emma report -r html -in coverage.em,
EMMA: processing input files ...
EMMA: 2 file(s) read and merged in 7 ms
EMMA: writing [html] report to [/root/Android_Application_source/testingProjectPackage/NotePad/bin/coverage/index.html] ...
root@ubuntu:~/Android_Application_source/testingProjectPackage/NotePad/bin# ls
AndroidManifest.xml                    AntNotePad-instrumented-unaligned.apk.d  AntNotePad.ap_.d  classes.dex  jarlist.cache
AndroidManifest.xml.d                  AntNotePad-instrumented.apk              build.prop        classes.dex.d  coverage.em  proguard.txt
AntNotePad-instrumented-unaligned.apk  AntNotePad.ap_                           classes           coverage       dexedLibs    res
root@ubuntu:~/Android_Application_source/testingProjectPackage/NotePad/bin# firefox ./coverage/index.html 
failed to create drawable

+ Recent posts