Android 测试工具集02

User scenario testing for Android(功能性测试框架)

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. With the support of Robotium, test case developers can write function, system and user acceptance test scenarios, spanning multiple Android activities.

See Questions & Answers for common Robotium questions and answers. 

See Getting Started for instructions and examples on how to create your first Robotium tests. 

Join the discussions in the Robotium Developers Group.

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. package com.luwenjie.helloworld.test; 
    2.  
    3. import android.test.ActivityInstrumentationTestCase2; 
    4. import com.luwenjie.helloworld.HelloWorldActivity; 
    5. import com.jayway.android.robotium.solo.Solo; 
    6.  
    7. public class HelloWorldTest extends ActivityInstrumentationTestCase2
    8. <HelloWorldActivity>{ 
    9.  
    10.     private Solo solo; 
    11.  
    12. //需要测试的app是什么?
    13. //这里需要测试com.luwenjie.helloworld包下的HelloWorldActivity这个应用
    14.  
    15.     public HelloWorldTest(){ 
    16.          super("com.luwenjie.helloworld", HelloWorldActivity.class); 
    17.     } 
    18.    
    19. //打开HelloWorld这个应用
    20.  
    21.     public void setUp() throws Exception{ 
    22.          solo = new Solo(getInstrumentation(), getActivity()); 
    23.     } 
    24.  
    25. //执行测试
    26. //searchText(String str):验证字符串是否存在
    27.  
    28.     public void testUI() throws Exception { 
    29.         boolean expected = true; 
    30.         boolean actual = solo.searchText("Hello") && solo.searchText("World"); 
    31.  
    32.         assertEquals("This and/or is are not found", expected, actual); 
    33.     } 

    34.  
posted @ 2015-02-12 19:51  狂奔的小狮子  阅读(176)  评论(0编辑  收藏  举报