Robotium 是一款基于Android instrumentation framework 的自动化测试工具库,功能十分强悍,而且上手简单,只要求有Junit基础即可。
先关注instrumentation 提供的三个基类:
1. SingleLaunchActivityTestCase 单activity测试实例,只调用setup和tearDown方法
2. ActivityUnitTestCase 单activity测试实例
3. ActivityInstrumentationTestCase2 针对多Activity测试或应用的功能性测试用例,可在UIThread中调用所有UI行为的API
怎么使用Robotium ?
在eclipse中新建Android Test Project,指定测试的项目,引入robotium-solo-4.x.jar,之后就可以编写测试单元了:
public class N001_TestIntorUserActivity extends ActivityInstrumentationTestCase2{ private Solo solo; public N001_TestIntorUserActivity() { super(DialerActivity. class); } @Override public void setUp() throws Exception { //setUp() is run before a test case is started. //This is where the solo object is created. solo = new Solo(getInstrumentation(), getActivity()); try { runTestOnUiThread( new Runnable() { @Override public void run() { getActivity().getTabHost().setCurrentTab(DialerActivity. TAB_INDEX_ACCOUNT); } }); } catch (Throwable e) { e.printStackTrace(); } } @Override public void tearDown() throws Exception { //tearDown() is run after a test case has finished. //finishOpenedActivities() will finish all the activities that have been opened during the test execution. solo.finishOpenedActivities(); } //第一个测试方法 public void testClickHelpbtn() throws Exception { for( int i=0; i<10; i++) { View helpBtn = solo.getView( "helpinfo_btn"); solo.clickOnView(helpBtn); solo.sleep(2000); solo.goBack(); } } //第二个测试方法 public void testChangeTabs() throws Exception { Random random = new Random(); for( int i=0; i<10; i++) { try { final int tabIndex = random.nextInt() % 4; runTestOnUiThread( new Runnable() { @Override public void run() { getActivity().getTabHost().setCurrentTab(tabIndex); } }); } catch (Throwable e) { e.printStackTrace(); } solo.sleep(2000); } } }
上面例子中,测试方法均以test开头,测试框架会自动调用。在测试方法中,我们就可以使用Robotium提供的API,实现具体的测试用例。
对于只有apk包的情况,一样可以使用Robotium对其进行测试。具体思路是先使用resign工具除去apk本身的签名,然后安装apk到目标环境,新建Android Test Project,修改项目AndroidManifest中的instrumentation字段,填入apk的包名即可:
<instrumentation android:name= "android.test.InstrumentationTestRunner" android:targetPackage= "com.cmnetphone" />
对比 MonkeyRunner 和 Robotium :
MonkeyRunner 优点:官方提供的测试工具,门槛极低,会写py脚本即可,适合重复性较强的UI测试或功能性测试。
缺点:API不完善,多限制,脚本执行性能差
Robotium 基于SDK中提供的测试框架,提供更为强大而方便的自动化测试API。要求懂得基本的Junit用法,某些场合可以完全取代 MonkeyRunner 所做白盒测试(如上面的例子),但同时也可以结合项目本身,编写测试单元,实现对代码逻辑的检查,以及输出结果的校验等测试。
共同点:
在白盒测试中,对于 MonkeyRunner 和 Robotium,建议结合 Hierarchy View 工具,分析测试目标视图的层次结构,设计具体测试用例。
相关推荐
一、测试目的 1、回归测试稳定版本功能。 2、提高工作效率。 二、测试对象 1、Robotium在APK(米聊)文件下进行java junit Test...7.插件:re-sign.jar,robotium-solo-3.3,robotium-solo-3.3-javadoc(官方文档)。
android TIPS小结android TIPS小结android TIPS小结android TIPS小结
Android自动化 Robotium 封装的小工具,简单修改就可以用
雾山的Robotium学习笔记---Robotium针对apk包的测试
Android自动化测试之Robotium学习
android-robotium-ant自动化测试框架搭建
android 自动化 robotium 文档wiki 和docs 。com.robotium.solo
Android自动化测试工具,从连接app到自动测试界面控件元素,非常详细!官网例子
在Android Studio上搭建的Robotium,经过简单修改,简单修改包名就可以使用,内有说明使用文档
详细的描述了android测试中Robotium使用的过程,包括Robotium测试项目的搭建,代码的编写,测试运行过程等
这是我收集的android自动化测试— 有关于robotium的一些资料 包括自己整理的一些文档 共4篇。。 jar也包括在内。 最重要的是还有一个Demo程序包,其中包括两个程序,一个测试程序一个被测程序。。 5分绝对值得的,...
android 黑盒 测试 工具框架 robotium jar包
Due to a number of different key features added to the Robotium Framework, it has become the world’s leading Android test automation framework and most of the industry experts and professionals are ...
This is a step-by-step, ... It's assumed that you have some experience in Android development, as well be familiar with the Android test framework, as Robotium is a wrapper to Android test framework.
NULL 博文链接:https://fanfq.iteye.com/blog/781769
robotium 截屏(截图)作用: 1.可用于实际测试结果与预期结果进行图片对比,以此判断测试结果正确性; 2.当Error发生后进行测试结果图片保存,以利于分析; 3.向Gallery、Camera等需要图片判断的测试部分提供支持。
最全最新的Android自动化测试Robotium详细说明文档,学习Robotium必不可少的资料。
android 数据库 小结 包括 增删改 等等…… 掌握这个基本掌握android数据库