星空网 > 软件开发 > 操作系统

Android junit单元测试

软件测试的分类
* 黑盒测试
* 测试逻辑业务
* 白盒测试
* 测试逻辑方法

根据测试粒度
* 方法测试:function test
* 单元测试:unit test
* 集成测试:integration test
* 系统测试:system test

根据测试暴力程度
* 冒烟测试:smoke test
* 压力测试:pressure test


新建android项目,新建Test.java文件,注意定义一个类继承一定要继承AndroidTestCase

Android junit单元测试images/loading.gif' data-original="http://images2015.cnblogs.com/blog/617081/201605/617081-20160528222859100-565928837.jpg" />

package com.wuyudong.juint.test;import com.wuyudong.juint.util.Utils;import android.test.AndroidTestCase;public class Test extends AndroidTestCase {    public void test() {    int res = Utils.add(3, 5);    assertEquals(8, res);  }}

新建工具包文件Utils.java

package com.wuyudong.juint.util;public class Utils {  public static int add(int a, int b) {    return a - b;  }}

运行项目,报错:

[2016-05-30 06:21:13 - 单元测试] 单元测试 does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library android.test.runner in its AndroidManifest.

在AndroidManifest.

<??><manifest ="http://schemas.android.com/apk/res/android"  package="com.wuyudong.juint"  android:versionCode="1"  android:versionName="1.0" >  <uses-sdk    android:minSdkVersion="8"    android:targetSdkVersion="17" />    <instrumentation     android:name="android.test.InstrumentationTestRunner"    android:targetPackage="com.wuyudong.juint"    ></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"/>    <activity      android:name="com.wuyudong.juint.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>  </application></manifest>

继续运行单元测试test,出现下面的断言异常

Android junit单元测试

双击跳转到

public class Test extends AndroidTestCase {    public void test() {    int res = Utils.add(3, 5);    assertEquals(8, res);  }}

 




原标题:Android junit单元测试

关键词:Android

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

数智跨境物流:https://www.goluckyvip.com/tag/92697.html
蚂蚁雄兵跨境物流:https://www.goluckyvip.com/tag/92698.html
乐鸟跨境物流:https://www.goluckyvip.com/tag/92699.html
南昌跨境电商:https://www.goluckyvip.com/tag/927.html
德纵跨境物流:https://www.goluckyvip.com/tag/92700.html
菲律宾跨境物流:https://www.goluckyvip.com/tag/92702.html
亚马逊以图搜图功能再更新,99%运营不知道!:https://www.kjdsnews.com/a/1842135.html
短视频广告剪辑技巧 :https://www.kjdsnews.com/a/1842136.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流