zoukankan      html  css  js  c++  java
  • Android:单元测试

    通过单元测试的方法可以轻松判断BUG

    第一步:首先在AndroidManifest.xml中加入下面红色代码:

    打开AndroidManifest.xml,选择instrumentation ,选择Name和Target packge

    <uses-sdk

    android:minSdkVersion="14"
    android:targetSdkVersion="19" />
    <instrumentation android:targetPackage="com.example.mysqldemo" android:name="android.test.InstrumentationTestRunner"></instrumentation>

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <uses-library android:name="android.test.runner"/>

     instrumentation 可以自己写也可以看下图操作:

    第二步:编写单元测试代码:

    一般对将要测试的方法命名testXXX,继承 AndroidTestCase,选择测试的方法右键点击,选择"Run As" - "Android Junit Test"。

    测试类的要求:

    1、测试类必须为public 

    2、测试类必须要有public修饰的无参构造器或者带一个String参数的构造器。带String参数的构造器第一行必须显式地写上super(String。

    3、测试方法返回值必须是void

    4、测试方法必须是public 

    5、测试方法必须是test开头,如testUpdate

    如果测试的时候遇上了这错误:

    Warning: No instrumentation runner found for the launch, using android.test.InstrumentationTestRunner

    解决方案:

    1.右击工程,选择Properties..

    2.在Run/Debug setting 删除所有的 launch configuration for ..

    相关文章:

    Android随笔:单元测试的好处

  • 相关阅读:
    推荐网址:Response.WriteFile Cannot Download a Large File
    为什么是 My?
    Fox开发杂谈
    DCOM配置为匿名访问
    连接到运行 Windows 98 的计算机
    OO面向对象以后是什么
    Com+的未来是什么?
    fox 表单和类库的加密及修复
    来自 COM 经验的八个教训
    VFP的加密问题
  • 原文地址:https://www.cnblogs.com/tinyphp/p/4030734.html
Copyright © 2011-2022 走看看