最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android學(xué)習(xí)筆記之應(yīng)用單元測試實例分析

 更新時間:2015年11月17日 11:39:38   作者:段殘夢  
這篇文章主要介紹了Android學(xué)習(xí)筆記之應(yīng)用單元測試,結(jié)合實例形式較為詳細(xì)的分析了Android單元測試的實現(xiàn)原理與具體步驟,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了Android學(xué)習(xí)筆記之應(yīng)用單元測試。分享給大家供大家參考,具體如下:

第一步:在AndroidManifest.xml中加入如下兩段代碼:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
  package="com.pccw" 
  android:versionCode="1" 
  android:versionName="1.0"> 
 <uses-sdk android:minSdkVersion="8" /> 
 <application android:icon="@drawable/icon" android:label="@string/app_name"> 
  <activity android:name=".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> 
  <!—添加代碼1--> 
  <uses-library android:name="android.test.runner"/> 
</application> 
 <!—添加代碼2--> 
  <instrumentation android:name="android.test.InstrumentationTestRunner" 
   android:targetPackage="com.pccw" android:label="aaa"/> 
</manifest>

1. <uses-library android:name="android.test.runner"/>代表把單元測試框架中的一些依賴庫引入進(jìn)來

2. <instrumentation android:name="android.test.InstrumentationTestRunner"android:targetPackage="com.pccw" android:label="aaa"/>代表配置單元測試框架的啟動裝置,啟動裝置有好幾個類,可以選擇,一般情況下我們使用上面這個。

3. targetPackage與上面的package相同,代表單元測試框架和當(dāng)前應(yīng)用是處于同一個進(jìn)程中

第二步:編寫業(yè)務(wù)邏輯,即需要被測試的模塊

public class PersonService { 
 public void save(String name){ 
  String sub = name.substring(6); 
 } 
 public int add(int a, int b){ 
  return a+b; 
 } 
}

第三步:編寫單元測試代碼

public class PersonServiceTest extends AndroidTestCase { 
 public void testSave() throws Exception { 
  PersonService service = new PersonService(); 
  service.save(null); 
 } 
 public void testAdd() throws Exception { 
  PersonService service = new PersonService(); 
  int result = service.add(1, 2); 
  Assert.assertEquals(3, result); 
 } 
}

第四步:打開eclipse中的outline窗口,其中會顯示單元測試類的所有的方法

然后想要測試哪個方法,則在哪個測試方法上右鍵鼠標(biāo),選擇Run As,然后再選擇Android JUnit Test即可,如果有異?;蛘咤e誤,則會出現(xiàn)如下情況:

如果是正常的,則會如下:

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

最新評論

麻江县| 成都市| 新野县| 芦溪县| 洛阳市| 武陟县| 东阿县| 嘉鱼县| 涪陵区| 美姑县| 汉源县| 防城港市| 克东县| 壶关县| 宕昌县| 平凉市| 昌平区| 大庆市| 定结县| 伊川县| 塘沽区| 武宣县| 江阴市| 波密县| 济宁市| 玛沁县| 含山县| 华阴市| 吉林省| 英超| 丰顺县| 城步| 安丘市| 和田县| 安溪县| 定安县| 金昌市| 潢川县| 肃南| 镇康县| 南康市|