標籤:android
一:測試的基本概念
根據源碼:
黑箱測試:注重過程和結果
白盒測試:根據源碼寫測試方法
測試的粒度:
方法測試:function test
單元測試:unit test
整合測試:
根據次數
煙霧測試 (Smoke Test)
壓力測試
二:搭建自己的測試架構
1. 業務代碼
publicclass CalcService {
publicint add(int x,int y){
return x+y;
}
}
2. 測試代碼
publicclass TestCalcService extends AndroidTestCase {
publicvoid testAdd()throws Exception{
CalcService service=new CalcService();
int sum=service.add(3, 5);
assertEquals(8, sum);
}
}
3. 搭建測試架構
<?xml version="1.0"encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android3"
android:versionCode="1"
android:versionName="1.0" >
<!-- 指令集需要在mainfest節點下 -->
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.android3"
/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- 在application節點下使用函數庫 -->
<uses-libraryandroid:name="android.test.runner"/>
<activity
android:name="com.example.android3.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<actionandroid:name="android.intent.action.MAIN" />
<categoryandroid:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
三:建立測試專案
四:測試的日誌資訊
Verbose: 提醒
Debug: 調試
Info: 資訊
Warn: 警告
Error: 錯誤
1. 修改上面的業務代碼
public class CalcService {
privateString tag="CalcService";
publicint add(int x,int y){
Log.v(tag, "x="+x);
Log.d(tag, "y="+y);
int result=x+y;
Log.i(tag,"result="+result);
Log.w(tag,"result="+result);
Log.e(tag,"result="+result);
returnx+y;
}
}
2. 添加測試過濾器
1. 運行測試代碼
記錄檔顯示:
著作權聲明:博主原創文章,轉載請說明出處。http://blog.csdn.net/dzy21
android基礎(6):junit測試