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 ...
随机推荐
- 三个线程ABC,交替打印ABC
转载与:https://www.cnblogs.com/x_wukong/p/4009709.html 创建3个线程,让其交替打印ABC . 输出如下: ABCABCABCABC. 方法:使用syn ...
- 【if控制器】-(某种情况成立就执行的场景)
if 控制器 一般来判断某种特殊情况 成立,就执行. JEXL Expression to evaluate:此处直接填写需要进行判断的表达式即可 表达式支持: == 是否等于,如${__jex ...
- 爬虫1.5-ajax数据爬取
目录 爬虫-ajax数据爬取 1. ajax数据 2. selenium+chromedriver知识准备 3. selenium+chromedriver实战拉勾网爬虫代码 爬虫-ajax数据爬取 ...
- array.some() 方法兼容ie8
在第 5 版时,some 被添加进 ECMA-262 标准:这样导致某些实现环境可能不支持它.你可以把下面的代码插入到脚本的开头来解决此问题,从而允许在那些没有原生支持它的实现环境中使用它.该算法是 ...
- 一个简单的Spring的AOP例子
目标对象的接口:IStudent.java 1 /** 2 * 3 */ 4 package com.dragon.study; 5 6 /** 7 * @author ...
- ZOJ 2532 Internship(最大流找关键割边)
Description CIA headquarter collects data from across the country through its classified network. Th ...
- Fox and Number Game
Fox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can ...
- 20172330 2017-2018-1 《Java程序设计》第三周学习总结
20172330 2017-2018-1 <Java程序设计>第三周学习总结 教材学习内容总结 这一章的主要内容是关于类与对象,通过对String类,Random类,Math类等一系列道德 ...
- A+B 输入输出练习I
while True: try: s=raw_input() a,b=s.split(' ') a,b=int(a),int(b) print a+b except EOFError: break A ...
- Uncaught ReferenceError: wx is not defined
程序的分享功能调用了微信的接口,但是忽然发现就报这个错误, Uncaught ReferenceError: wx is not defined 同时下方还有这个错误 This content sho ...