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 ..

  • 相关阅读:
    Codeforces round 493 Convert to Ones
    石子合并系列问题【区间dp,环形,四边不等式优化】
    UVa 10635
    选课【树形dp】
    JSOI2016病毒感染
    加分二叉树【树形dp】
    人为什么活着__稻盛和夫的哲学
    213. House Robber II
    安装 error: Microsoft Visual C++ 14.0 is required 解决方案
    ImportError:no mudle named 'cv2'
  • 原文地址:https://www.cnblogs.com/kluan/p/4826235.html
Copyright © 2011-2022 走看看