转一篇老外写的博文:Android automated testing (Robotium)
Robotium的中文资料甚少,只得求助于老外,发现了一篇不错的文章:https://blog.codecentric.de/en/2011/03/android-automated-testing-robotium/
但是不知道是不是公司网络问题,codecentric网站打开超慢,故转Mihal Celovski的博文到这里备用,向原作者致敬!
开始正文:
In the previous GWT project we worked with acceptance tests and the Robot Framework. The question I asked myself was if something similar exists for Android. Yes, it exists, and its name is Robotium.
Robotium is a test framework created to write robust automatic black-box test cases for Android applications. With the support of Robotium,
test case developers can write function, system and acceptance test
scenarios, spanning multiple Android activities. It allows you to create
test cases for Android Activities, Dialogs, Toasts, Menus and Context
Menus etc.
This is one very simple example how to write Robotium tests:
- Create an Android test project if one does not exist (explained earlier in my post: Android testing in brief).
- Create a test class. For example, if you want to test activity
“MyAndroidActivity”, your test class then needs to extend
android.test.ActivityInstrumentationTestCase2.
public class MyAndroidActivityTest extends android.test.ActivityInstrumentationTestCase2 { |
- Download robotium-solo-xxx.jar library or add a dependency to it in the *.pom file of your maven project. It’s open source at Google Code.
- Declare a Solo class instance. When writing tests there is no need to plan for or expect new activities in the test case. All is handled automatically by Robotium-Solo. Robotium-Solo can be used in conjunction with ActivityInstrumentationTestCase2. The test cases are written from a user perspective were technical details are not needed.
private Solo solo; |
- Create a test class constructor.
public MyAndroidActivityTest() { |
- Override the setUp() and tearDown() methods. Overriden setUp() method is usually the place where you instantiate Solo object. In teardDown() method solo.finalize() is called and all activites that have been opened are finished.
@Override |
- Create a test method. Robotium-Solo offers a number of methods for testing various UI events such as: clickOnText(), enterText(), clearEditText, goBack, serachText() etc.
public void testDisplayedText() throws InterruptedException { |
As you can see it is all very similar to Robot-Selenium tests. When you decide to run this test you have to start the Emulator or connect an actual device to your computer. Then you just select your test class and select Run As/ Android JUnit test. After that you can see your application start and some actions execute. The JUnit view in your Eclipse window shows the current progress and success of the test runs.
Robotium benefits
Robotium tests have great readability compared to standard instrumentation tests. No great knowledge of the tested application is needed, just things like the name of the Activity, displayed texts or anything related to application’s UI. But one of the greatest benefits for us is the possibility to integrate tests with Maven as part of continuous integration.
更新部分博主的问答:
Shivang Seth says:
Would you elaborate on how to write test cases for an application having multiple activities/services. Should we extend the test case classes from android.test.ActivityInstrumentationTestCase2 or android.test.InstrumentationTestCase? An example would be very handy. Thank you
solo.clickOnButton(“Start Activity1″); // start the first activity
Assert.assertTrue(solo.searchText(“Some text on Activity1″));
Assert.assertTrue(getActivity().getString(R.string.activity1_title)
.equals(solo.getCurrentActivity().getTitle()));
solo.goBack(); // go back to start page(activity)
solo.clickOnButton(“Start Activity2″); // start the second activity
…
转一篇老外写的博文:Android automated testing (Robotium)的更多相关文章
- Android application testing with the Android test framework
目录(?)[-] Android automated testing 1 How to test Android applications Tip 2 Unit tests vs functional ...
- 【Android开发日记】之入门篇(十二)——Android组件间的数据传输
组件我们有了,那么我们缺少一个组件之间传递信息的渠道.利用Intent做载体,这是一个王道的做法.还有呢,可以利用文件系统来做数据共享.也可以使用Application设置全局数据,利用组件来进行控制 ...
- csdn肿么了,这两天写的博文都是待审核
昨天早上8点写了一篇博文,然后点击发表,结果系统显示"待审核".于是仅仅好qq联系csdn的客服,等到9点时候,csdn的客服上线了,然后回复说是链接达到5个以上须要审核,于是回到 ...
- 【朝花夕拾】Android性能篇之(六)Android进程管理机制
前言 Android系统与其他操作系统有个很不一样的地方,就是其他操作系统尽可能移除不再活动的进程,从而尽可能保证多的内存空间,而Android系统却是反其道而行之,尽可能保留进程.An ...
- 关于Java多线程的线程同步和线程通信的一些小问题(顺便分享几篇高质量的博文)
Java多线程的线程同步和线程通信的一些小问题(顺便分享几篇质量高的博文) 前言:在学习多线程时,遇到了一些问题,这里我将这些问题都分享出来,同时也分享了几篇其他博客主的博客,并且将我个人的理解也分享 ...
- Flex xml编辑器(老外写的)
github上的一个项目老外写的xml编辑器,灵活利用了Tree的labelFunction实现节点运行时展现.开源地址是 https://github.com/softinsure/XML-Edit ...
- 写一些有关android的东西吧,那时候玩android时候的一些笔记
写一些有关android的东西吧,那时候玩android时候的一些笔记
- 转---秒杀多线程第十四篇 读者写者问题继 读写锁SRWLock
在<秒杀多线程第十一篇读者写者问题>文章中我们使用事件和一个记录读者个数的变量来解决读者写者问题.问题虽然得到了解决,但代码有点复杂.本篇将介绍一种新方法——读写锁SRWLock来解决这一 ...
- 封装一个帮助类来写文件到android外置存储器上
项目地址:点击打开 项目简介:写文件到android外置存储器的一个帮助类,和它的demo程序 它是如何工作的呢? 1.创建 AppExternalFileWriter 对象并传递context(上下 ...
随机推荐
- 黑马程序员——OC语言 三大特性之继承
Java培训.Android培训.iOS培训..Net培训.期待与您交流! (以下内容是对黑马苹果入学视频的个人知识点总结) 三大特性之继承 (一)继承的基本用法 先建立个Animal再用Dog继承前 ...
- c#基础知识-2
1.在控制台接受数据时可以这样输入: using System; using System.Collections.Generic; using System.Linq; using System.T ...
- fifo read
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types. ...
- jQuery--checkbox全选
jQuery.attr 获取/设置对象的属性值,如: $("input[name='chk_list']").attr("checked"); //读 ...
- TopCoder----卖柠檬
1. 题目描述 Problem Statement You are playing a game called Slime Tycoon.You will be selling Slimonade ...
- codeforces 666A (DP)
题目链接:http://codeforces.com/problemset/problem/666/A 思路:dp[i][0]表示第a[i-1]~a[i]组成的字符串是否可行,dp[i][1]表示第a ...
- 18、SQL提高篇(变量的使用 拓展)
一 例题 例题用表:[cost] 注:费用类型个数不定 将上图所示的表根据type列的类型转为下图样式 *用变量将类型名分组动态提取的方法: ) set @sql1='' select @sql1= ...
- iOS-Gdata XML解析配置和简单使用
简单介绍使用废话少说直接上图就能看明白... 导入libxml2,使用第三方AFNetworking网络请求,第三方XML解析GData GData需要的配置 Build Settings 里搜索,添 ...
- Thrift 个人实战--Thrift 的序列化机制
前言: Thrift作为Facebook开源的RPC框架, 通过IDL中间语言, 并借助代码生成引擎生成各种主流语言的rpc框架服务端/客户端代码. 不过Thrift的实现, 简单使用离实际生产环境还 ...
- bootstrap-4
html文档中,列表结构主要有三种:有序列表.无序列表和定义列表:<ul><li>.<ol><li>.<dl><dt><d ...