我的测试人生........

【转】android 单元测试出现错误及改正

上一篇 / 下一篇  2013-07-15 23:00:35 / 个人分类:移动测试

http://www.51testing.com/html/65/n-848765.html

1.Test run failed:Instrumentation run failed due to 'java.lang.ClassNotFoundException'

  原因是找不到单元测试的类,后来经过仔细看代码及网上查找终于解决,现在记录下来便于以后查找解决办法,问题简单下次就记得了,但是做的项目多了,问题也多了就易忘记或遗漏,好记性不如烂笔头真的一点不错。从头再来,遇到问题就记录下来。

  解决方法:打开androidmanifest.xml文件在<activity> **** </activity>之间加上配置

<!-- 单元测试配置 -->
<uses-library android:name="android.test.runner" />

别忘了导入junit4包

  2. Caused by:java.lang.ClassNotFoundException: android.test.InstrumentationTestRunner in loader dalvik.system.PathClassLoader[/data/app/tyrj.lr.sqliteapply-1.apk:

  解决办法:在androidmanifest.xml文件的</application>标签之前加上

<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="tyrj.lr.sqliteapply" >

  这里的包设置和此xml文件的最上面的Package设置相同

  </instrumentation>

  3.android.content.res.Resources$NotFoundException: String resource ID

  在执行sqlite查询数据操作时出现错误,通过错误信息找到错误代码行,原来是利用cursor游标获得Int 类型的数据没有转换,编译器没通过,不能得到游标获取到的值。

  错误行: int id = cursor.getColumnIndex("id");

  int age = cursor.getColumnIndex("age");

  解决:

int id = cursor.getInt(cursor.getColumnIndex("id"));
int age = cursor.getInt(cursor.getColumnIndex("age"));

  这两天出现的错误可不少,一些知识都忘了,哎真是一天不学习就忘得一干二净,这样的小错误一而再再而三的错,希望记载下来,以后出现的错误就不再错了,祈祷!!!

document.write(''.replace(/%url%/,encodeURIComponent(location.href)));

TAG:

 

评分:0

我来说两句

日历

« 2024-04-21  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 309819
  • 日志数: 243
  • 建立时间: 2011-07-13
  • 更新时间: 2018-07-15

RSS订阅

Open Toolbar