Android:单元测试Junit的配置
来源:互联网 发布:如何做好淘宝客服 编辑:程序博客网 时间:2024/05/16 12:20
在实际开发中,开发android软件的过程需要不断地进行测试。而使用Junit测试框架,是正规Android开发的必用技术,在Junit中可以得到组件,可以模拟发送事件和检测程序处理的正确性..........
第一步:首先在AndroidManifest.xml中加入下面代码:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android_db" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <!-- 记住这个一要放在application外面,不然会出现配置错误 信息 --> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.example.android_db"> </instrumentation> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <!-- 在本应用中导入需要使用的包,放在application里面activity外面 --> <uses-library android:name="android.test.runner"/> <activity android:name="com.example.android_db.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类)
</pre><p></p><p><span style="font-family: Arial; font-size: 14px; line-height: 26px;"><span style="font-family: Arial; font-size: 14px; line-height: 26px;"><span style="font-family: Arial; font-size: 14px; line-height: 26px;"><strong></strong></span></span></span></p><pre name="code" class="html">package com.example.android_db;import android.test.AndroidTestCase;public class MyTest extends AndroidTestCase{public MyTest(){}public void createDB(){MyDbOpenHelper myDbOpenHelper=new MyDbOpenHelper(getContext());myDbOpenHelper.getWritableDatabase();}}
选择要测试的方法,右键点击“Run As”--“Android Junit Test”。
0 0
- Android:单元测试Junit的配置
- Android:单元测试Junit的配置
- Android:单元测试Junit的配置
- Android:单元测试Junit的配置
- Android:单元测试Junit的配置
- Android单元测试Junit的配置
- Android:单元测试Junit的配置
- Android:单元测试Junit的配置
- Android:单元测试Junit的配置
- Android:单元测试Junit的配置
- Android:单元测试Junit的配置
- Android:单元测试Junit的配置
- Android:单元测试Junit的配置
- Android:单元测试Junit的配置
- Android:单元测试Junit配置
- Android下的junit单元测试
- Android下的junit 单元测试
- Android下的Junit单元测试
- Implement strStr()
- POJ 1017 Packets(积累)
- 服务器遇到的问题总结
- Linux线性地址空间的划分及内核寻址方式
- 具有选择框的菜单
- Android:单元测试Junit的配置
- 关于“NetWorkOnMainThreadException”错误
- 解决eclipse中logcat不显示log的问题
- SDUT 1225-编辑距离(串型dp)
- Oracle起步学习(七)--组函数
- 在SurfaceView中绘制文本时 无法自动换行问题的解决办法
- Code Blocks IDE
- poj 3263 Tallest Cow(线段树)
- HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效。