以百度下载的QQ apk为例
一、APK重签名
1、下载resign.jar
2、将apk拖入resign.jar中
3、出现错误如下:
解决方法:
下载zipalign.exe,并放入/sdk/tools中
4、重复执行步骤2
二、Robotium运行
1、将已重签名的apk安装到模拟器
2、新建Eclipse工程–>Android Test Project–>输入工程名–>选择This Project–>选择Android SDK 版本–>Finish
3、放入Robotium.jar包
(1)新建文件夹libs
(2)放入robotium-solo-5.4.1.jar
(3)将robotium-solo-5.4.1.jar加入biuld path
4、新建Class
代码如下:
package eu.fbk.se.androidmonkey.test;
import com.robotium.solo.Solo;
import android.R.string;
import android.test.ActivityInstrumentationTestCase2;
import android.test.InstrumentationTestRunner;
@SuppressWarnings("rawtypes")
public class Demo extends ActivityInstrumentationTestCase2{
private static final String activityName = "com.tencent.mobileqq.activity.SplashActivity";
private static final String packageName = "com.tencent.mobileqq";
private static int a= 0;
private static int b = 2;
public static Class<?> LanucherActivityClass;
static{
try {
LanucherActivityClass = Class.forName(activityName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
public Demo() {
super(LanucherActivityClass);
// TODO Auto-generated constructor stub
}
private Solo solo;
@Override
protected void setUp() throws Exception {
// TODO Auto-generated method stub
super.setUp();
if(solo == null){
solo = new Solo(getInstrumentation(),getActivity());
}
}
public void testOpenWallet(){
solo.pressMenuItem(0);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
a += countTestCases();
if(a >= b) {
solo.finishOpenedActivities();
}
}
}
在AndroidManifest.xml中修改instrumentation的targetpackage,如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.fbk.se.androidmonkey.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="17" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.tencent.mobileqq" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
</manifest>
5、run as Android JUnit test
参考图书:
http://yuedu.baidu.com/ebook/29c97c724b73f242326c5f0b?fr=aladdin&key=Robotium
PS:
期间出现另一个问题:
package xxx does not have a signature matching the target xxx
解决方法:
在系统变量中创建变量:
ANDROID_SDK_HOME
值:c盘下面的keystore,如:C:\Users\jane\.android