Android 单元测试
2015-12-19 20:38
435 查看
1.在AndroidManifest.xml添加权限问题:
a. <instrumentation android:targetPackage="com.example.hz15"
android:name="android.test.InstrumentationTestRunner"></instrumentation>
b.在activity之外添加<uses-library android:name="android.test.runner"/>
2.创建测试类:
继承AndroidTestCase类
3.随便看下例子:
package com.example.test;
import java.util.List;
import com.example.domain.Person;
import com.example.service.DBservice;
import com.example.service.PersonService;
import android.test.AndroidTestCase;
import android.util.Log;
public class PersonTest extends AndroidTestCase {
private static final String TAG = "PersonTest";
public void testCreateDB() throws Exception{
DBservice dbservice = new DBservice(getContext());
dbservice.getWritableDatabase();
}
public void testAddData() throws Exception{
PersonService ps = new PersonService(getContext());
for(int i = 10; i < 20; i++){
Person person = new Person(i, "hhzz"+i, "159123456"+i,0);
ps.addDate(person);
}
}
public void testDeleteDate() throws Exception{
PersonService ps = new PersonService(getContext());
Integer id = 9;
ps.deleteData(id);
}
public void testUpdateData() throws Exception{
PersonService ps = new PersonService(getContext());
//
// Person person = new Person();
//
// person.setId(2);
// person.setName("xia");
// person.setPhone("123456789");
//
// ps.updateData(person);
ps.updateData(new Person(1, "HZ1", "6456546", 100));
ps.updateData(new Person(2, "HZ2", "123778456789", 90));
}
public void testFind() throws Exception{
PersonService ps = new PersonService(getContext());
Person result = ps.findData(5);
Log.i(TAG, result.toString());
}
public void testGetCount() throws Exception{
PersonService ps = new PersonService(getContext());
long count = ps.getCount();
Log.i(TAG, String.valueOf(count));
}
public void testGetScrollData()throws Exception{
PersonService ps = new PersonService(getContext());
List<Person> persons = ps.getScrollDate(0, 9);
for(Person person:persons){
Log.i(TAG, person.toString());
}
}
public void testPayment() throws Exception{
PersonService ps = new PersonService(getContext());
ps.payment();
}
}
a. <instrumentation android:targetPackage="com.example.hz15"
android:name="android.test.InstrumentationTestRunner"></instrumentation>
b.在activity之外添加<uses-library android:name="android.test.runner"/>
2.创建测试类:
继承AndroidTestCase类
@Override public void setUp() throws Exception { super.setUp();//写测试方法之前执行的条件 } @Override public void tearDown() throws Exception { super.tearDown();//写测试方法之后执行关闭功能 }
3.随便看下例子:
package com.example.test;
import java.util.List;
import com.example.domain.Person;
import com.example.service.DBservice;
import com.example.service.PersonService;
import android.test.AndroidTestCase;
import android.util.Log;
public class PersonTest extends AndroidTestCase {
private static final String TAG = "PersonTest";
public void testCreateDB() throws Exception{
DBservice dbservice = new DBservice(getContext());
dbservice.getWritableDatabase();
}
public void testAddData() throws Exception{
PersonService ps = new PersonService(getContext());
for(int i = 10; i < 20; i++){
Person person = new Person(i, "hhzz"+i, "159123456"+i,0);
ps.addDate(person);
}
}
public void testDeleteDate() throws Exception{
PersonService ps = new PersonService(getContext());
Integer id = 9;
ps.deleteData(id);
}
public void testUpdateData() throws Exception{
PersonService ps = new PersonService(getContext());
//
// Person person = new Person();
//
// person.setId(2);
// person.setName("xia");
// person.setPhone("123456789");
//
// ps.updateData(person);
ps.updateData(new Person(1, "HZ1", "6456546", 100));
ps.updateData(new Person(2, "HZ2", "123778456789", 90));
}
public void testFind() throws Exception{
PersonService ps = new PersonService(getContext());
Person result = ps.findData(5);
Log.i(TAG, result.toString());
}
public void testGetCount() throws Exception{
PersonService ps = new PersonService(getContext());
long count = ps.getCount();
Log.i(TAG, String.valueOf(count));
}
public void testGetScrollData()throws Exception{
PersonService ps = new PersonService(getContext());
List<Person> persons = ps.getScrollDate(0, 9);
for(Person person:persons){
Log.i(TAG, person.toString());
}
}
public void testPayment() throws Exception{
PersonService ps = new PersonService(getContext());
ps.payment();
}
}
相关文章推荐
- Android抓包方法(一)
- Android studio Cannot reload AVD list问题解决
- 【Android】Android Studio 进行代码混淆,打包release APK
- android动画 属性动画详解
- Android Service完全解析,关于服务你所需知道的一切
- Android下创建一个输入法
- 安卓开发学习之019 创建自定义视图
- android中setImageResource加载大图片出现oom解决方案
- Android官方文档翻译 十八 4.2Pausing and Resuming an Activity
- Android中的Intent简单使用
- IOS android 1px边框
- android 圆角图标 和不规则圆角(边框)
- Android命名规范
- Android点滴---ViewHolder通用,优雅写法
- Android图片保存后不显示
- Android自定义View(六)——打造更完美的侧滑
- android通用適配器
- AndroidStudio 快捷键使用总结大全
- Android onActivityResult获取返回值的用法
- Android中自定义View的使用注意