Android JUnit test
Android单元测试步骤
1.修改AndroidManifest.xml文件.
添加instrumentation节点.其中name是固定值,targetPackage为需要测试的类所在的包.如:
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.ahai.sqlitedemo"
在application节点下添加 <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.ahai.sqlitedemo"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" /> <instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.ahai.sqlitedemo" >
</instrumentation> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.ahai.sqlitedemo.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> <uses-library android:name="android.test.runner" />
</application> </manifest>
2.编写测试类,继承自AndroidTestCase. 此类可以引用getContext等方法,非常方便. 如:
package com.ahai.sqlitedemo;
import android.test.AndroidTestCase;
import com.ahai.sqlitedemo.dao.PersonDao;
public class SqlTestCase extends AndroidTestCase {
public void insert() {
Person person = new Person("xiaojiang");
PersonDao personDao = new PersonDao(getContext());
personDao.Insert(person);
}
}
3.测试代码,如测试insert方法,在Package Explorer中,右击-Run As-Android JUnit Test.
4.常见错误
(1)Test run failed: Unable to find instrumentation target package:
出现这个错误是由于manifest中指定的package值,与android:targetPackage不一致导致.需要将两个修改为一致,并将测试类移到其中再测试.
Android JUnit test的更多相关文章
- Android Junit测试框架
对应用进行单元测试: 使用Junit测试框架,是正规Android开发的必用技术.在Junit中可以得到组件,可以模拟发送事件和检测程序处理的正确性. 1.配置指令集和函数库: (1)配置指令集,指定 ...
- 在Android Studio进行“简单配置”单元测试(Android Junit)
起因 在Android studio 刚出.本人就想弄单元测试,可惜当时Android studio不知道抽什么风(准确来说,应该是我不会弄而已).无法执行到相应的代码.后来今天突然自己又抽风.又想去 ...
- Android JUnit Test——批量运行测试代码
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ Android测试三要素 写Android测试用例有三要素,一是我们用的“安卓模拟器device” ...
- Android JUnit 入门指南
自动化单元测试可以做许多的事,并帮你节省时间.它也可以被用作快速检验新建工程或进行冒烟测试.始终,单元测试是作为一种有效的.系统的检验应用程序各功能执行的方式.Android SDK支持JUnit的自 ...
- 1.Android JUnit Runner(使用AndroidStudio)
一.Android JUnit Runner介绍 1.Android JUnit Runner 1)是一个测试运行器,用于运行Junit3和Junit4的Android测试包 2)替换Instrume ...
- Android -- junit测试框架,logcat获取log信息
1. 相关概念 白盒测试: 知道程序源代码. 根据测试的粒度分为不同的类型 方法测试 function test 单元测试 unit test 集成 ...
- Android+Junit单元测试1
学习参考: http://my.oschina.net/liux/blog/52469 http://mobile.51cto.com/android-229614.htm 一,权限配置 <ap ...
- android jUnit test 进行自动化测试
一. 被test的工程: 新建一个android工程:D_session:它有一个activity:D_sessionActivity:package名:com.mysession 二.测试工程: 新 ...
- Android之如何使用JUnit进行单元测试
转的:http://www.blogjava.net/qileilove/archive/2014/05/19/413824.html Android中如何使用JUnit进行单元测试 在我们日常开发a ...
随机推荐
- Spring Cloud(五):Hystrix 监控面板【Finchley 版】
Spring Cloud(五):Hystrix 监控面板[Finchley 版] 发表于 2018-04-16 | 更新于 2018-05-10 | 在上一篇 Hystrix 的介绍中,我们提到 ...
- [HNOI2017]大佬
参考题解 \(\text{Solution}\) 我们发现5个行为中2操作与其它操作无关,所以我们采用贪心,尽量让多的时间去攻击大佬. 设 \(f[i][j]\) 表示前 \(i\) 天剩 \(j\) ...
- Java算法2
实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 分析:若从前向后遍历的话,那Happy后面 ...
- day-15 用opencv怎么扫描图像,利用查找表和计时
一.本节知识预览 1. 怎样遍历图像的每一个像素点? 2. opencv图像矩阵怎么被存储的? 3. 怎样衡量我们算法的性能? 4. 什么是查表,为什么要使用它们? 二.什么是查表,为什么要使 ...
- block知识总结
一.block在内存中存在的形式 1.当把block句法写在函数或者方法外面时,系统会在静态数据区分配一块内存区域给block对象.这片区域在程序执行期会一直存在. 2.当block句法写在函数或者方 ...
- 什么是BCL
原文: 原文:https://www.cnblogs.com/1996V/p/9037603.html 什么是BCL 当你通过VS创建一个项目后,你这个项目就已经引用好了通过.NET下的语言编写好的一 ...
- Debian实验机 常用命令
1.开启中文输入法 fcitx 2. 开启无线连接 wicd 3. 远程连接 ssh root@XXX.XXX.XXX.XXX 4. 启动Ulipad ~/ulipad-master# python ...
- iOS-Masonry用法
__weak typeof(self) weakSelf = self; UIView * tempView = [[UIView alloc]init]; NSInteger count = ;// ...
- C# 执行bat文件
private void RunBat(string batPath) { Process pro = new Process(); FileInfo file = new FileInfo(batP ...
- 【week3】psp (技术随笔)
本周psp: 随笔字数: 总计 累计代码行 (前两项为单元测试部分) 词频统计:87 四则运算:49 四人小组:39 175 随笔字数 (不包含代码字数) 词频统计:237 四则运算:125 四人小组 ...