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 studio导入开源项目
  2. Android CTS 测试研究
  3. app测试教程:ios与android的区别
  4. [android]android自动化测试八之让你的AVD无法连接网络
  5. android 测试必备 -adb 工具的使用
  6. Android http超时选项的测试
  7. Android studio 新建项目后报错:Could not GET 'https://dl.googl
  8. Android自动化测试之Monkey工具
  9. ReactNative入门-Android原生项目转RN项目

随机推荐

  1. Android(安卓)驱动之旅 (Based on Galaxy
  2. 我是如何自学Android,资料分享(2015 版)
  3. Android(安卓)通过百度地图SDK 实现地图
  4. android ANR产生原因和解决办法
  5. SystemServer分析
  6. Android(安卓)系统框架介绍
  7. LeakCanary使用详细教程(附Demo)
  8. Android(安卓)创建定时任务
  9. Android中通过view.getContext获取Activi
  10. Android中JNI的使用方法