Robotium测试系统APK
来源:互联网 发布:交换机压力测试软件 编辑:程序博客网 时间:2024/05/17 01:52
学习了Robotium之后,很少使用,几乎都忘记了。于是想着,写个文档记录一下。
1.下载Robotium最新的JAR包
https://github.com/robotiumtech/robotium
2.由于我是测试系统APK,无源码,所以跳过“导入被测应用到eclips”这一步骤,直接打开eclips->new Project->Android Test Project->填好项目名称后->选择This project(没有被测代码,故选择此项)->finish。
3.右键选中我们项目->new->folder->lib,手动拷贝我们1步骤下载的jar包,如robotium-solo-5.2.1.jar到lib文件夹下,右键项目名->build Path->Configure Build Path再导入刚刚复制的robotium-solo-5.2.1.jar包。
4.开始配置我们的AndroidManifest.xml文件,主要修改instrumentation。
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.android.settings" />
android:name中默认的是android.test.InstrumentationTestRunner,如果你有设置传参则把此文件修改成你实际的传参类,一般为"包名.InstrumentationTestRunner"。
android:targetPackage则是被测APK包名,我这里主要想测的wifi,于是是系统设置的包名。
查看包名可以通过sdk\tools下面的hierarchyviewer.bat或者uiautomatorviewer.bat均可以查看。(连接样机,双击bat即可)
注:AndroidManifest.xml文件有两个地方涉及包名,
其中<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxx.xxx.xxx.xxx"的包名对应的你自己所编写的包名,而instrumentation对应的包名是被测应用的。
5.选中包名,开始new一个Junit Test Case,根据自己请款选择Junit版本,我这里选择Junit4,完全之后,在Configure Build Path导入Junit4。
6.开始编写测试用例:以下是一个直接点击WLAN的简单例子。
package com.example.wifi.test;
import static org.junit.Assert.*;
import android.test.ActivityInstrumentationTestCase2;
import org.junit.Test;
import com.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
@SuppressWarnings("rawtypes")
public class TestWifi extends ActivityInstrumentationTestCase2{
private static final String ACTIVITY_CLASSNAME =
"com.android.settings.Settings";
private Solo solo;
private static Class<?> launcherActivityClass;
static{
try{
launcherActivityClass=Class.forName(ACTIVITY_CLASSNAME);
}
catch (ClassNotFoundException e)
{
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public TestWifi() {
super(launcherActivityClass);
// TODO Auto-generated constructor stub
}
@Test
public void test() {
trunOnWifi();
}
private void trunOnWifi() {
// TODO Auto-generated method stub
solo.clickOnText("WLAN");
}
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
}
7.编写完成后,选中项目->右键->Android Tools->Export unsigned Application Package到与系统签名文件同一个文件夹下。
8.例子中所用的是SettingAPK,故使用Android系统的platform签名。
输入命令 java -jar signapk.jar platform.x509.pem platform.pk8 xx.apk xx_new.apk来重新签名,签系统签名。注:
signapk.jar:是/platform/build/tools/signapk/编译出,在/out/host/linux-x86/framework/中。
platform.pk8 platform.x509.pem:Android采用RSA签名算法来给应用签名,其中platform.pk8为私钥,platform.x509.pem为公钥。可在/platform/build/target/product/security/目录下找到。
9.adb install xx_new.apk 后,使用命令adb shell am instrument -w 包名/android.test.InstrumentationTestRunner运行。
- Robotium测试系统APK
- robotium 测试apk包
- robotium 测试APK包
- robotium测试apk
- Android Robotium测试APK方法
- robotium测试单独APK包
- Android Robotium测试单个的APK方法
- robotium测试apk包修改签名问题
- Robotium只有apk文件时进行测试
- Robotium只有apk文件时进行测试
- Robotium只有apk文件时进行测试
- Robotium只有apk文件时进行测试
- Android Robotium测试单个的APK方法
- robotium测试APK 遇到过的坑
- Robotium 测试Android apk安装包
- robotium—只有apk文件的测试
- robotium—只有apk文件的测试
- robotium—只有apk文件的测试
- Spring 实现数据库读写分离
- 使用 pandas 玩转股票数据
- 判断一棵树是不是另外一棵树的子树(dfs)
- Kotlin 变量和属性
- BZOJ-4205 卡牌配对 最大流+线性筛+神建模
- Robotium测试系统APK
- Cg入门21:Fragment shader - 2D纹理采样
- ORB+暴力匹配
- JdbcTemplate注解注入
- 遍历map
- JVM中的flag设置
- Hadoop 使用combiner提升性能
- zabbix配置点
- Xcode安装插件