Android--单元测试
来源:互联网 发布:淘宝新店开直通车 编辑:程序博客网 时间:2024/04/27 23:10
单元测试环境搭建:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.db.demo" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <instrumentation android:targetPackage="com.db.demo" android:name="android.test.InstrumentationTestRunner" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".DBActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <uses-library android:name="android.test.runner" /> </application></manifest>
对上篇文章的数据库中的业务类进行测试:
package com.db.demo;import java.util.List;import android.test.AndroidTestCase;import android.util.Log;public class PersonServiceTest extends AndroidTestCase {public void testCreateDB() throws Throwable {DBOpenHelper dbOpenHelper = new DBOpenHelper(this.getContext());dbOpenHelper.getWritableDatabase();}public void testInsert() throws Throwable {PersonService ps = new PersonService(this.getContext());Person p = new Person();p.setName("abc");ps.insert(p);p = new Person();p.setName("def");ps.insert(p);p = new Person();p.setName("ghi");ps.insert(p);p = new Person();p.setName("dd");ps.insert(p);p = new Person();p.setName("ff");ps.insert(p);p = new Person();p.setName("ee");ps.insert(p);p = new Person();p.setName("ww");ps.insert(p);p = new Person();p.setName("hh");ps.insert(p);p = new Person();p.setName("jj");ps.insert(p);p = new Person();p.setName("uu");ps.insert(p);}public void testUpdate() throws Throwable {PersonService ps = new PersonService(this.getContext());Person p = new Person();ps.update(p);}public void testDelete() throws Throwable {PersonService ps = new PersonService(this.getContext());ps.delete(1);}public void testFind() throws Throwable {PersonService ps = new PersonService(this.getContext());Person p = ps.find(1);Log.d(AppConstant.TAG, p.toString());}public void testGetScrollData() throws Throwable {PersonService ps = new PersonService(this.getContext());List<Person> persons = ps.getScrollData(0, 3);for(Person person : persons) {Log.d(AppConstant.TAG, person.toString());}}public void testGetCount() throws Throwable {PersonService ps = new PersonService(this.getContext());Log.d(AppConstant.TAG, ps.getCount() + "");}}
- android 单元测试
- Android单元测试
- Android单元测试
- android单元测试
- Android单元测试
- Android单元测试
- android单元测试
- android单元测试
- Android单元测试
- Android单元测试
- android 单元测试
- android 单元测试
- Android--单元测试
- android单元测试
- Android单元测试
- Android单元测试
- Android单元测试
- ANDROID 单元测试
- UDP网间通讯(不同局域网之间通讯) UDP打洞详细过程 图文
- 推荐十个最好的Java性能故障排除工具:
- QC集成LDAP指南
- 增加附件上传功能
- bada开发tips
- Android--单元测试
- Flex3自定义事件(笔记)
- 【转】windows下mysql日志开启与查询
- Linux打包命令
- EditText的属性
- ListView笔记
- 5V电源被误当12V电源用,核心板可以正常工作,外设异常
- java实用ZIP压缩和解压类
- PAZU-- 4Fang WEB 打印控件