The required environment:
1. Eclipse
2. Android Development tools (ADT)
3. Software develoment Kit (SDK)
4. JDK
5, Robotium
1-4 of the environment content for the Android application of the new development environment of the building process, no longer repeat.
Download of the Robotium jar package:
Http://code.google.com/p/robotium/downloads/list Download the jar package: Robotium-solo-3.1.jar (of course there will be an update)
1. Create a project in eclipse:
Android Project:
Android Application project, File, new, project, next
(1) Set the app name, project name, and package name in new Android application
(2) Select the SDK version and minimum version of SDK for development use
Then step by step to finish.
Android Test Project:
The official website can create a project called Test Engineering:
Setting name, Next, select Test Target window, File---new, project--------Android test project, Next, choose the Proj to be tested ECT or select this project after next, finish
In this case, the new project will have the initial package in Src.
Note: If there is no other Android project in the space, a new test project project will make an error. The solution is to create a new Android Application project project with nothing in it.
The above two projects in my opinion there is not much difference, that is, the package name may be different, the test project will follow the selected project in the package name plus a test into a package. Androidmanifest.xml is not the same, you can change the androidmanifest.xml to test when you do the test.
2, under the project to create a new Libs folder, the folder contains the required package, we only need to add the download Robotium package.
3, in the build path inside the Robotium package plus can
4, modify androidmanifest.xml for the following form
<?xml version= "1.0" encoding= "Utf-8"?>
<!--package is a test pack name that needs to be set by itself--
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "testpackage"
Android:versioncode= "1"
Android:versionname= "1.0" >
<!--set the class to run, This is specified as Android.test.InstrumentationTestRunner-->
<!--targetpackage Specifies the package name of the test-->
<!--The following paragraph must be-->
<instrumentation
Android:name= " Android.test.InstrumentationTestRunner "
android:targetpackage=" packagetotest "/>
<!--note the need <uses-library> this is required-->
< Application
android:icon= "@drawable/ic_launcher"
Android : label= "@string/app_name",
<uses-library android:name= "Android.test.runner"/
</application>
</manifest>
5. Create a new class file in the test package we set up
Import Java.io.BufferedReader;
Import Java.io.FileReader;
Import java.io.IOException;
Import Android.test.ActivityInstrumentationTestCase2;
Import Com.jayway.android.robotium.solo.Solo;
Must inherit from ActivityInstrumentationTestCase2 class
public class Test1 extends activityinstrumentationtestcase2{
private static final String target_package_id = target_package;//You need to specify the name of the package you want to test
private static final String launcher_activity_full_classname =target_launcher;// You specify the class name of the startup app
private static class Launcheractivityclass;
private solo solo;
static{
try
{
launcheractivityclass=class.forname ( Launcher_activity_full_classname);
}&NBSP;
catch (ClassNotFoundException e) {
throw new RuntimeException (e);
}
} /span>
constructor, you need to call Super's construct
Public Testnumber () {
Super (Target_package_id,launcheractivityclass);
TODO auto-generated Constructor stub
}
Test case, need to start with test, this is junit3 previous definition
Public Test1 () {
Solo.clickonscreen (555,555);
}
@Override
public void SetUp () throws Exception {
TODO auto-generated Method Stub
Solo = new solo (Getinstrumentation (), getactivity ());
}
@Override
public void TearDown () throws Exception {
TODO auto-generated Method Stub
try{
Solo.finishopenedactivities ();
}catch (Throwable e) {
E.printstacktrace ();
}
Super.teardown ();
}
}
Follow the above method to write the use case.
6, because the signature of the test project needs to be the same as the signature of the package we get, so we need to re-sign.
(1) Unzip the APK package and delete the Meta-inf folder inside
(2) package deleted from Meta-inf folder is. apk file
(3) In the DOS interface, go to the APK folder you want to test, then run:
Jarsigner-keystore/debug.keystore-storepass android-keypass testapkname.apk command to install
8. Right mouse button in eclipse, run as---Android Junit test mode.
Automated testing of Android apps using Robotium