Previous robotium tests were based on source code. When we can't get the android source code, we can use another way to test. Regarding this method, the robotium wiki has relevant information for reference RobotiumForAPKFiles:Use Robotium when only having apk
http://code.google.com/p/robotium/wiki/RobotiumForAPKFiles
Before implementing the entire testing process, let's take a brief look at Android application signatures:
Why do Android apps need to be signed? What is the purpose of the signature?
The role of the signature:
(1) Authentication of sender identity
(2) Ensure the integrity of the input information
(3) Prevent denials in transactions
Robotium starts the testing process:
1. Change the APK signature
According to the robotimu wiki introduction: we need to use a tool called re-sign.jar, which can help us re-sign an APK.
Download: http://down.51cto.com/data/443499
1. Double-click re-sign.jar or java -jar re-sign.jar under cmd
2. Drag the application into the re-sign, here is an example of "Youdao Dictionary 3.1.0.apk"
3. Generate new signature and new APK.
Youdao Dictionary 3.1.0_dubug.apk
Package name:com.youdao.dict
Main activity:com.youdao.dict.activity.DictSplashActivity
2. Install "Youdao Dictionary 3.1.0_dubug.apk" into the android virtual machine
1. Enter android-sdk-windows\platform and execute the command:
adb install Youdao Dictionary 3.1.0_dubug.apk
2. After the installation is successful, the virtual machine will see this application.
3. Modify the AndroidMainfest.xml file
Create Android test project: http://luwenjie.blog.51cto.com/925779/908886
- <?xmlversion="1.0"encoding="utf-8"?>
- <manifestxmlns:android="http://schemas.android.com/apk/res/android"
- package="com.luwenjie.helloworld.test"
- android:versionCode="1"
- android:versionName="1.0">
- //Add supports-screens
- <supports-screens android:anyDensity="true"/>
- <uses-sdkandroid:minSdkVersion="10"/>
- //Modify targetPackage to the previously produced Package Name
- <instrumentation
- android:name="android.test.InstrumentationTestRunner"
- android:targetPackage="com.youdao.dict"/>
- <application
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name">
- <uses-libraryandroid:name="android.test.runner"/>
- </application>
- </manifest>
Fourth, modify the test framework:
The testing framework Robotium Wiki already provides:
//TARGET_PACKAGE_ID and LAUNCHER_ACTIVITY_FULL_CLASSNAME using tool generated
private static final String TARGET_PACKAGE_ID = "com.youdao.dict"
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.youdao.dict.activity.DictSplashActivity"
//Test script, we can modify the script and use java features to create multiple script files for calling
public void testCanOpenSettings(){
solo.enterText(0, "test");
}
Five, run the script to test
This article is from the " Xiao Maozi " blog, please keep this source http://xiaomaozi.blog.51cto.com/925779/922261