Eclipse中Android单元测试

  说说正常的代码吧   1)   1: java 测试
<span style="font-size:14px;">package com.medivh.app; public class Person { public String sub(String username) { String sub = username.substring(3); return sub; } public int add(int a,int b) { return a+b; } }</span>
  2:
<span style="font-size:14px;">package com.medivh.app; import org.junit.Test; import junit.framework.Assert; import android.test.AndroidTestCase; public class PersonTest extends AndroidTestCase { @Test public void testSub() throws Exception { Person p = new Person(); p.sub(null); } public void testAdd() throws Exception { Person p = new Person(); int result = p.add(1, 4); Assert.assertEquals(result, 6); } } </span>
 2)AndroidManifest.xml
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.medivh.app" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name"> <activity android:name=".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> <span style="color:#FF0000;"><uses-library android:name="android.test.runner" /></span> </application> <uses-sdk android:minSdkVersion="8" /> <span style="color:#FF0000;"><instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.medivh.app" android:label="Tests for My App" /></span> </manifest> </span>
   3)测试   右键项目Run as.. Android Junit Test 就会出结果   开始的时候犯迷糊结果各种出错:   No instrumentation runner found for the launch, using android.test.InstrumentationTestRunner   First does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library android.test.runner in its AndroidManifest.xml   is not configured correctly for running tests   到网上各种查,发现配置没错啊。最后才发现问题出在我居然眼睛进沙子一般修改了bin下面的AndroidManifest.xml,可能是我前面打开了这个目录,结果就随意打开了它修改了它。希望大家以后小心行事。

更多相关文章

  1. Appuim运行Android真机自动化测试
  2. [置顶] 强烈推荐转载-Android 性能测试
  3. Android 单元测试实战(1)—— 调研与选型
  4. [置顶] android自动化测试之Benckmark
  5. 安卓系统的开发与测试
  6. Android之monkey Test,Monkey测试中的黑名单和白名单,Monkey测试
  7. 介始一下Android 单元测试框架类----ActivityInstrumentationTes
  8. android studio查找应用控件id实现自动化测试

随机推荐

  1. Ansible入门
  2. 如何给脚本写一个守护进程?
  3. Django模型1对多和多对多关系
  4. DG中归档日志删除遇警告
  5. 闲聊容器的日志
  6. 介绍一款好用的终端工具 Screen
  7. Ansible入门之Playbook
  8. 努力无用论?我不信。。。
  9. nginx+uwsgi+django环境搭建
  10. django1.8数据迁移