Android Testing Fundamentals 2, robotium, uiautomator, monkeyrunner and monkey

如Robotium官方wiki所说, Robotium是一个开源自动测试框架, 它使得黑盒(和白盒)的UI测试变得很easy。 Robotium is an Android test automation framework that has full support for native and hybrid applications. Robotium makes it easy to write powerful and robust automatic black-box UI tests for Android applications.

快速测试case:
启动xx app,进首页
选择"分类xx", 进分类页
选择"影片xx",进详情页
选择播放,进播放页
播放
向前seek
向后seek

对应脚本及使用心得:
    solo.unlockScreen();
        Thread.sleep(300);
        solo.clickOnText("分类xx");// so easy, 如果用Activity的单元测试ActivityInstrumentationTestCase2类, 会涉及大堆的findViewById的调用
        Thread.sleep(500);
        solo.clickOnText("电视剧");
        Thread.sleep(500);
        solo.clickOnText("影片xx");
        Thread.sleep(500);
        solo.clickOnText("播放");
        Thread.sleep(500);
        solo.drag(300, 1000, 660, 660, 30);// seek bar, positon is got by eclipse dump view
        Thread.sleep(10000);
        solo.clickLongOnScreen(100, 100);// to prevent the seekbar hide
        solo.drag(1000, 500, 660, 660, 30);


Ref and demo see: 
http://code.google.com/p/robotium/
http://blog.51cto.com/zt/301


VS


Android UI test framework (http://developer.android.com/tools/testing/testing_ui.html)
The Android SDK provides the following tools to support automated, functional UI testing on your application:
    uiautomatorviewer - A GUI tool to scan and analyze the UI components of an Android application.
    uiautomator - A Java library containing APIs to create customized functional UI tests, and an execution engine to automate and run the tests.
    Android SDK Platform, API 16 or higher
(Seem to be powerful, TODO to try...)


VS


Monkey and monkeyrunner (http://developer.android.com/tools/help/monkeyrunner_concepts.html, http://developer.android.com/tools/help/monkey.html)
"monkey", is a command-line tool that sends pseudo-random streams of keystrokes, touches, and gestures to a device.
The monkeyrunner tool is an API and execution environment for test programs written in Python.



Summary:
Robotium, test one apk, need resign apk;
uiautomator, requires API 16 or higher;
Monkey, just pseudo-random streams of events;
monkeyrunner, seems to be powerful;



More reading,
http://my.oschina.net/u/435726/blog/201076
http://itindex.net/detail/50270-android-uiautomator-%E8%87%AA%E5%8A%A8%E5%8C%96
http://fengbohaishang.blog.51cto.com/5106297/962705

你可能感兴趣的:(android,test,unit)