Android Automation Test (2) Robotium Environment Construction and beginners Tutorial

Source: Internet
Author: User

Robotium environment Construction and beginner's introductory tutorial

    • Preparation tool: Robotium data download
    • Knowledge Preparation:
    1. Java fundamentals, such as basic data structures, syntax structures, classes, inheritance, and more
    2. Familiarity with Android, understanding four components, writing simple Android apps
    3. Familiarize yourself with the Eclipse IDE use method
    4. Have enough patience with the spirit of exploration, encounter problems can be skilled Google
    • Environment construction
    1. Install JDK, configure environment variables, if not please Google
    2. Download and install the Android SDK and update
    3. Download Eclipse and install the ADT plugin, integrated with the Android SDK
    • Robotium Beginner
    1. Download the Robotium official example and the latest JAR package
    2. Open Eclipse Import tested project

      Click to view larger image

    3. Create a test project: Select Android Test Project and click Next

      Click to view larger image

    4. Enter the project name and click Next

      Click to view larger image

    5. Select the project Notepad to be tested and click Finish

      Click to view larger image

    6. Create a new Lib folder in the test project

      Click to view larger image

    7. Copy the downloaded Robotium jar package into Lib and bring the jar package to the project in Build path

      Click to view larger image

    8. Open the Manifest.xml file in the test project and modify the following

      Click to view larger image

    1. Create a new JUnit test case, select JUNIT4, enter the class name, and click Done

      Click to view larger image

    2. Open the newly created test class, modify the inheritance Activityinstrumentationtestcase2<noteslist>, create a constructor method, and write the test code, specifically

      Click to view larger image

01 packagecom.example.android.notepad.test;
02
03 importandroid.test.ActivityInstrumentationTestCase2;
04
05 importcom.example.android.notepad.NotesList;
06 importcom.jayway.android.robotium.solo.Solo;
07
08 publicclassNotePadTest extendsActivityInstrumentationTestCase2
09 {
10     privateSolo solo;//声明Solo
11     publicNotePadTest()//构造方法
12     {
13         super(NotesList.class);
14
15     }
16
17     @Override
18     publicvoid setUp() throwsException
19     {
20         solo = newSolo(getInstrumentation(), getActivity());
21     }
22
23     @Override
24     publicvoid tearDown() throwsException
25     {
26         solo.finishOpenedActivities();
27     }
28
29     publicvoid testAddNote() throwsException
30     {
31         //点击add note按钮
32         solo.clickOnMenuItem("Add note");
33         //比对结果
34         solo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor");
35         //在第一个TextEdit控件上输入内容
36         solo.enterText(0, "Note 1");
37         //返回上个界面
38         solo.goBack();
39         //点击菜单中的Add note
40         solo.clickOnMenuItem("Add note");
41         //在第一个EditText中输入内容
42         solo.enterText(0, "Note 2");
43         //返回NotesList activity
44         solo.goBackToActivity("NotesList");
45         //截屏
46         solo.takeScreenshot();
47         booleanexpected = true;
48         booleanactual = solo.searchText("Note 1") ; solo.searchText("Note 2");
49         assertEquals("Note 1 and/or Note 2 are not found", expected, actual);
50
51     }
52
53 }
    1. After writing, open the emulator or connect to the real machine, right-click the test class, select Android JUnit test

      Click to view larger image

    2. Eclipse switches to the JUnit interface, where the emulator (the real machine) automatically executes the test and the results are visible through the left interface

      Click to view larger image

    3. A simple test is over. If you do not have a problem, then congratulate you continue to learn further, if you have problems, do not hurry ~ Please make sure that you do not have any errors in the process, and then I list the errors you may encounter, if you have not resolved please Google or contact us
1, the most common: Java.lang.NoClassDefFoundError:com.jayway.android.robotium.solo.Solo solution: After operation and clean project

Android Automation Test (2) Robotium Environment Building and beginners tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.