Android 的开发可以说已经遍地都是,不说精致的app,只要看些书,看点教学视频,学习二至三个月,都可以随便开发几个小项目,当然只能是自娱自乐的。最近突然想起了,关于android 的自动化测试,于是网上搜了相关资料学习,最后决定先尝试 robotium。

robotium wiki:http://code.google.com/p/robotium/w/list

这里有篇文章对于robotium的介绍很贴切:robotium 是 android 自带类 Instrumentation 的一个封装,方便测试人员直接调用封装好的接口,也就是说,实际上我们直接使用Instrumentation 也能够进行自动化测试,但robotium可以简化我们的测试步骤,我们只需要调用某个robotium的API,传几个参数,就等于我们在调用一部分的Instrumentation帮我们实现测试。robotium 就是富二代!!高帅富!!

http://www.51testing.com/?uid-22381-action-viewspace-itemid-238847

需要注意:

1.测试项目:例如:HelloWorldTest,Build Path需要导入robotium-solo.jar包

2.Eclipse:3.7 版本,需要勾选Order and Export中的内容

        
  1. packagecom.luwenjie.helloworld.test;
  2. importandroid.test.ActivityInstrumentationTestCase2;
  3. importcom.luwenjie.helloworld.HelloWorldActivity;
  4. importcom.jayway.android.robotium.solo.Solo;
  5. publicclassHelloWorldTestextendsActivityInstrumentationTestCase2
  6. <HelloWorldActivity>{
  7. privateSolosolo;
  8. //需要测试的app是什么?
  9. //这里需要测试com.luwenjie.helloworld包下的HelloWorldActivity这个应用
  10. publicHelloWorldTest(){
  11. super("com.luwenjie.helloworld",HelloWorldActivity.class);
  12. }

  13. //打开HelloWorld这个应用
  14. publicvoidsetUp()throwsException{
  15. solo=newSolo(getInstrumentation(),getActivity());
  16. }
  17. //执行测试
  18. //searchText(String str):验证字符串是否存在
  19. publicvoidtestUI()throwsException{
  20. booleanexpected=true;
  21. booleanactual=solo.searchText("Hello")&&solo.searchText("World");
  22. assertEquals("Thisand/orisarenotfound",expected,actual);
  23. }
  24. }

更多相关文章

  1. Android内核驱动——电源管理
  2. js调用android本地代码失败 兼容问题
  3. Android(安卓)APK应用安装原理(1)-解析AndroidManifest原理-Pack
  4. 友盟深坑分享
  5. Android(安卓)Studio上方便使用butterknife注解框架的偷懒插件An
  6. android 启动默认的邮件客户端,多附件的问题
  7. Android桌面小部件与RemoteViews
  8. Android(安卓)UI学习 - 对话框 (AlertDialog & ProgressDialog)
  9. Flutter移动开发UI框架理解(一)

随机推荐

  1. Android FrameLayout
  2. Android获取RecyclerView滑动距离
  3. Android Handler消息处理机制面试5连问
  4. Android拨打电话权限总结
  5. Android中am命令用法
  6. Android(安卓)AlertDialog 无法弹出输入
  7. Android之自定义ProgressBar
  8. Android编译系统(三):官方文档Android Bu
  9. Android中短信拦截解决方案
  10. listview圆角实现