Android单元测试设置
2015-11-26 16:59
393 查看
很简单的东西,但是总是忘记。记一笔
添加在Application外部的内容:
其中的
添加在Application内Activity外的内容:
添加完成之后的配置文件:
例如对获取系统应用信息的一个功能类进行的测试:
最后部署运行的时候以
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即可
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories