Android 测试工具集02

时间:2022-10-16 09:03:07

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中的内容

Android 测试工具集02

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