Android Test---robotium----simple example

Source: Internet
Author: User

1. First create a project to be tested, named "Robotium"; a very simple Android app; The main page has only a TextView control;

2. Building a project for testing, named "Robotiumtestcase"; check if there is a word like "hello" or "World" on the page of the apk being tested;

2.1 Choose file-"new--" project----"Android test Project"

2.2 Enter the name of the test project Robotiumtestcase

2.3 Select the tested project "Robotium" and click Finish to complete the creation of the test project;

2.4 Create a new test case for testing. Right-click on the newly created project to select---new---->class------"Finish

3. Import Robotium;

3.1 Save the downloaded Robotium-solo-xxx.jar to the Libs in the root of the test project, if no new Libs folder can be created;

3.2 Add Robotium-solo-xxx.jar to the reference path of the test project, right-click Test Project----SELECT----"Build path----" Configure build;

3.3 In the dialog box that pops up the Java build path, select the TAB option for libraries------"Click Add External JARS ... The button to add the Robotium-solo-xxx.jar you just saved in step 3.1

3.4 Same In the Java Build Path dialog box, select the TAB option for Orderand export----"Select Robotium-solo-xxx.jar and make it sticky;

Steps in detail

4. Add the Kaiyuan library Robotium-solo-xxx.jar, the next is to write test cases , check the main page whether there is a word;

The code is as follows:

 Packagecom.example.robotium.test;ImportCom.robotium.solo.Solo;ImportAndroid.test.ActivityInstrumentationTestCase2; Public classTestextendsActivityInstrumentationTestCase2 {PrivateSolo solo;  PublicTest ()throwsException {Super(Class.forName ("Com.example.robotium.MainActivity")); //TODO auto-generated Constructor stub} @Overrideprotected  voidSetUp ()throwsException {solo=NewSolo (Getinstrumentation (), getactivity ()); } @Overrideprotected  voidTearDown ()throwsException {solo.finishopenedactivities (); }             Public voidTest Case ()throwsexception{Booleanexpected =true; BooleanActual =solo.searchtext ("Debbie") &&solo.searchtext ("Xie")); Assertequals ("Debbie is isn't found", expected, actual); }    }

5. The final thing is to run our test project. Right-click the test project and select Run as-----> andriod junit Test. When the execution is complete, you will see a test result;

The result is wrong, because the APK being tested has no "Debbie" or "Xie" except for the words "Hello World"

Android Test---robotium----simple example

Related Article

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.