Android单元测试设置
来源:互联网 发布:java微信开发框架 编辑:程序博客网 时间:2024/06/11 08:21
很简单的东西,但是总是忘记。记一笔
Manifest文件添加内容
需要分别在Manifest文件中添加两个部分,一个是在Application外部,另外一个是在Application内Activity外部。具体添加部分如下:
添加在Application外部的内容:
其中的targetPackage
根据实际的包路径填写,label随意
<instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.zp.shortshot" android:label="Junit Test" />
添加在Application内Activity外的内容:
<uses-library android:name="android.test.runner"/>
添加完成之后的配置文件:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.zp.shortshot" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <!-- 第一个添加-- > <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.zp.shortshot" android:label="Junit Test" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <!-- 第二个添加-- > <uses-library android:name="android.test.runner"/> <activity android:name="com.zp.shortshot.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
编写测试用例
配置之后就可以进行测试用例的编写了,测试用例需要继承AndroidTestCase
类
例如对获取系统应用信息的一个功能类进行的测试:
public class TestGetAppInfo extends AndroidTestCase { public void getApps() throws Exception { AppInfoProvider provider = new AppInfoProvider(getContext()); List<AppInfo> infos = provider.getAllApps(); for (AppInfo info : infos) { System.out.print("name : " + info.getName()); System.out.println("\t pkgName : " + info.getPkgName()); } } }
最后部署运行的时候以Android Junit Test
即可
0 0
- Android单元测试设置
- android 单元测试
- Android单元测试
- Android单元测试
- android单元测试
- Android单元测试
- Android单元测试
- android单元测试
- android单元测试
- Android单元测试
- Android单元测试
- android 单元测试
- android 单元测试
- Android--单元测试
- android单元测试
- Android单元测试
- Android单元测试
- Android单元测试
- Python中简单的正则表达式
- 数据结构 — 图 之 拓扑排序 (AOV网)
- 兔子-查看当前php的版本
- [Javascript] XHTML VS HTML , Document type
- linux .o .a .so文件解析
- Android单元测试设置
- AngularJS进阶(十)AngularJS改变元素显示状态
- 内存
- NSMotification通知使用方法
- 用纯Java代码根据IP获取windows和linux的MAC物理地址
- 1.python学习笔记:python连接mysql数据库
- PHP从某个关联数组中取出某一列KEY的值并放入另一个数组中
- uva201_Squares
- android学习笔记15 - Application中的name作用