Android 漫游之路------Android下junit单元测试、logCat的使用
来源:互联网 发布:安阳淘宝客服公司招聘 编辑:程序博客网 时间:2024/05/18 15:03
---------------------- 路漫漫其修远兮,吾将上下而求索。学无止境!----------------------
Android下junit单元测试
软件测试小知识:
根据测试是否知道源代码:
黑盒测试:只关心程序执行的过程和结果
白盒测试:根据源代码写测试方法或者测试用例。
根据测试的粒度:
方法测试:function test
单元测试:unit test
集成测试:intergration test
根据测试的次数:
冒烟测试:smoke test(android 猴子)
压力测试:prssure test
Android单元测试:
1.Android测试类要继承AndroidTestCase类
2.写测试方法,在测试方法内使用断言assert来测试要测试的方法
3.在AndroidManifest.xml中,要设置
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.lee.test" />
和<uses-library android:name="android.test.runner" >
4.确保adb连接正常。
MyService.java
package com.lee.test.service;public class MyService {/** * 计算器相加的业务 * @param a * @param b * @return */public int add(int a,int b){return a+b;}}
TestMyService.java
package com.lee.test.service.test;import com.lee.test.service.MyService;import android.test.AndroidTestCase;public class TestMyService extends AndroidTestCase {/** * add方法的测试代码 * 把异常抛给测试框架 * @throws Exception */public void testAdd()throws Exception{MyService myService = new MyService();int retVal = myService.add(3, 5);//断言,预期结果是8,实际结果是retValassertEquals(8, retVal);}}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.lee.test" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <!-- 这里是进行单元测试必须要添加,指令集必须在manifest节点下 --> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.lee.test" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.lee.test.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节点下,使用函数库 --> <uses-library android:name="android.test.runner" > </uses-library> </application></manifest>
logCat的使用
日志信息是分等级的:
verbose:提醒 黑色
debug:调试 蓝色
info:信息 绿色
warn:警告 橙色
error:错误 红色
使用上面的程序,可以做一个demo
修改MyService.java
package com.lee.test.service;import android.util.Log;public class MyService {private static final String TAG = "MyService";/** * 计算器相加的业务 * @param a * @param b * @return */public int add(int a,int b){Log.v(TAG, ""+a);Log.d(TAG, ""+b);Log.i(TAG, ""+b);Log.w(TAG, ""+a);Log.e(TAG, ""+b);System.out.println("System.out的log");System.err.println("System.err的log");return a+b;}}
运行测试后,对logCat中的log通过配置l过滤器进行过滤
---------------------- 路漫漫其修远兮,吾将上下而求索。学无止境!----------------------
我的博客:http://blog.csdn.net/helloxiaobi
- Android 漫游之路------Android下junit单元测试、logCat的使用
- Android下的junit单元测试
- Android下的junit 单元测试
- Android下的Junit单元测试
- Android单元测试之JUnit
- Android 单元测试之JUnit
- Android 使用Junit单元测试
- Android-使用Junit单元测试
- android 中使用单元测试 Junit的步骤
- Android单元测试(一):JUnit框架的使用
- Android Studio下JUnit单元测试
- Android单元测试(三):JUnit单元测试框架的使用
- Android单元测试(三):JUnit单元测试框架的使用
- android 开发之 Junit单元测试
- Android 使用 Junit进行单元测试
- android使用junit进行单元测试
- Android使用JUnit进行单元测试
- 【安卓笔记】------logcat以及android junit的使用
- Python Challenge(6--7关)——我的解题报告(running with python3.x)
- 程序员求职攻略(《程序员面试笔试宝典》)之面试笔试技巧?
- POJ 2352 - Stars 排序后用树状数组处理+离散化
- 【HZOI】 Path
- json 使用详细教程
- Android 漫游之路------Android下junit单元测试、logCat的使用
- ios开发-應用程式的設定檔info.plist
- Android源代码分析(三) MediaScanner源码分析(下)
- 【HZOI】 赏花
- Android开发之向应用程序界面绑定数据
- 111
- about commonjs module
- 2
- asdf