android 单元测试
来源:互联网 发布:cnnic证书 知乎 编辑:程序博客网 时间:2024/05/16 00:57
在主配置文件中加入权限:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.mytool" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.SEND_SMS" /> <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.example.mytool.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> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.example.mytool" /><!--引入权限 targetPackage 改为单前包名--></manifest>
测试类代码
package com.example.mytool;import android.test.AndroidTestCase;import android.util.Log;public class mceshi extends AndroidTestCase {private String TAG="mceshi";public void mtext1() throws Throwable{/* this.getContext() 获取上下文对象 */Log.i(TAG,"ok");}}
测试访问其他应用数据
package com.example.ftext;import java.io.ByteArrayOutputStream;import java.io.FileInputStream;import android.test.AndroidTestCase;import android.util.Log;public class fangwenceshi extends AndroidTestCase {private String TAG="fangwenceshi";public void fanggwenceshi() throws Throwable{String path="/data/data/com.example.mytool/files/liyihang.txt";FileInputStream duqu=new FileInputStream(path);ByteArrayOutputStream neicun=new ByteArrayOutputStream();byte[] buf=new byte[1024];int len=0;while((len=duqu.read(buf))!=-1){neicun.write(buf,0,len);}duqu.close();neicun.close();String result=new String(buf,"GBK");Log.i(TAG,result);}}
0 0
- android 单元测试
- Android单元测试
- Android单元测试
- android单元测试
- Android单元测试
- Android单元测试
- android单元测试
- android单元测试
- Android单元测试
- Android单元测试
- android 单元测试
- android 单元测试
- Android--单元测试
- android单元测试
- Android单元测试
- Android单元测试
- Android单元测试
- ANDROID 单元测试
- 继承的访问控制_保护继承_保护继承(C++语言)
- 如何查看端口号被哪个进程占用
- IPC与TCP/IP应用及比较
- 项目管理系统
- button设置边框
- android 单元测试
- Dev Treelist控件显示行号
- hdu 1195
- ios 获取所有字体列表-日记
- 九度_题目1384:二维数组中的查找
- 二叉树的操作(二叉树的创建、先序遍历--->先根、中序遍历---->先左、后续遍历--->后根)
- Alpha、Beta、RC、GA版本的区别
- javaMail发送邮件
- UVA 11401 - Triangle Counting 组合