在AndroidManifest.xml文件中增加两个东西,分别是:

1、uses-library ,位于application里面。

2、instrumentation,与application同级。

【注】

android:targetPackage是指要测试的应用所在的包即应用的Activity所在的包。

android:name为用于跑TestCase的类。

完整的AndroidManifest.xml文件如下:

<?xml version="1.0" encoding="utf-8"?>  <manifest xmlns:android="http://schemas.android.com/apk/res/android"        package="com.lzb.study.db"        android:versionCode="1"        android:versionName="1.0">      <application android:icon="@drawable/icon" android:label="@string/app_name">          <!-- 单元测试 -->          <uses-library android:name="android.test.runner" />          <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>        </application>        <!-- 启动测试器 -->      <instrumentation android:name="android.test.InstrumentationTestRunner"          android:targetPackage="com.lzb.study.db" android:label = "Tests for My App" />    </manifest>   

然后,建立测试类。测试类中的测试方法必须以test开头。如:

public class PersonServiceTest extends AndroidTestCase {            public void testSave() throws Exception {          PersonService ps = new PersonService(this.getContext());          Person person = new Person();          person.setName("李刚");          person.setAge((short)0);          ps.save(person);                }  }  

然后在test类中,选中testcase,点击右键,选择Run As --> Android Junit Test,开始执行case。



更多相关文章

  1. Android单元测试
  2. Ubuntu下查找.android/avd
  3. 转-Android数据存储(总结篇)
  4. Eclipse Jar包源码关联
  5. Android(安卓)SDK下载慢的解决办法
  6. Android(安卓)客户端发送邮件(JMail方式)
  7. Android(安卓)Eclipse JNI 调用 .so文件加载
  8. Android(安卓)常用开发工具类
  9. 面试例题6:两种方法将图像显示在View上

随机推荐

  1. Android控件之ListView
  2. Android-menu键选项菜单的实现
  3. 熟悉Android---canvas第一笔
  4. [置顶] Android系统移植与调试之------->
  5. Android:LayoutInflater的使用
  6. android 使用websocket 实现简单的聊天。
  7. Android中GUI系统的Event路由机制
  8. The source attachment does not contain
  9. 【Java&Android开源库代码剖析】のAndroi
  10. android之activity切换