qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          Android單元測試方法與步驟

           一、修改配置文件AndroidManifest.xml
          <? xml version="1.0" encoding="utf-8" ?>
          < manifest  xmlns:android ="http://schemas.android.com/apk/res/android"
          package ="cn.ycmoon.test.activity"  android:versionCode ="1"
          android:versionName ="1.0" >
          < uses-sdk  android:minSdkVersion ="8"   />
          < application  android:icon ="@drawable/icon"  android:label ="@string/app_name" >
          < uses-library  android:name ="android.test.runner"   />
          < 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 >
          </ application >
          < instrumentation  android:name ="android.test.InstrumentationTestRunner"
          android:targetPackage ="cn.ycmoon.test.activity"  android:label ="Testing"   />
          </ manifest >
            說明:1、在Application節點中Activity前添加   <uses-library android:name="android.test.runner" />
            2、在Application節點的添加  <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="cn.ycmoon.test.activity" android:label="Testing" />
            二、在相應包中編寫要完方法,
            三、在src同級級目錄中添加一個test文件夾[可自定義],并在下建立和項目一致的包名: cn.ycmoon.test.activity
            四、在要進行單元測試的方法上右鍵->NEW->JUNIT Test Case。彈出下界面:
            選擇 SuperClass為:
           點擊下一步,選擇要測試的方法:
            點擊完成。
            將新產生的單元測試的類放入test/項目包名下。
            在單元測試方法中添加實現:
            展開test/cn.ycmoon.test.activity下單元測試類,選擇要測試的方法,點右鍵,選擇Run As->Android JUnit Test,就會打開單元測試結果界面。
            右該方法無錯誤,則結果會顯示綠色狀態條:
           

          posted on 2014-08-18 09:34 順其自然EVO 閱讀(432) 評論(0)  編輯  收藏 所屬分類: android

          <2014年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 通化县| 云梦县| 韩城市| 静乐县| 秭归县| 玛曲县| 江城| 宣汉县| 亳州市| 天全县| 涞水县| 孝昌县| 习水县| 静海县| 敦煌市| 阿拉尔市| 遂宁市| 台安县| 江山市| 凤庆县| 得荣县| 桃江县| 鹤壁市| 马尔康县| 平昌县| 德阳市| 清远市| 潮安县| 镶黄旗| 吉木萨尔县| 呼和浩特市| 喀喇沁旗| 大关县| 桂阳县| 班戈县| 通化市| 浦北县| 花莲县| 阿拉善盟| 邹平县| 疏勒县|