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