qileilove

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

          Android:單元測試Junit的配置

           在實際開發中,開發android軟件的過程需要不斷地進行測試。而使用Junit測試框架,側是正規Android開發的必用技術,在Junit中可以得到組件,可以模擬發送事件和檢測程序處理的正確性..........

            第一步:首先在AndroidManifest.xml中加入下面代碼:

          <?xml version="1.0" encoding="utf-8"?>
          <manifest xmlns:android=http://schemas.android.com/apk/res/android
          package="hb.learn.junit"
          android:versionCode="1"
          android:versionName="1.0">
          <uses-sdk android:minSdkVersion="8" />
          <application android:icon="@drawable/icon" android:label="@string/app_name">

          <!-- 在本應用中導入需要使用的包,放在application里面activity外面 -->
          <uses-library android:name="android.test.runner" />

          <activity android:name=".JunitTestActivity"
          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>

          <!-- 記住這個一要放在application外面,不然會出現配置錯誤 信息 -->
          <instrumentation android:name="android.test.InstrumentationTestRunner"
          android:targetPackage="hb.learn.junit" android:label="Tests for My App" />
          </manifest>

            上面targetPackage指定的包要和應用的package相同。就是這個測試類所在的包名;

            第二步:編寫單元測試代碼(選擇要測試的方法,右鍵點擊“Run As”--“Android Junit Test” ):

          import android.test.AndroidTestCase;
          import android.util.Log;
          public class XMLTest extends AndroidTestCase {
          public void testSomething() throws Throwable {
          Assert.assertTrue(1 + 1 == 3);
          }
          }


           在實際開發中,開發android軟件的過程需要不斷地進行測試。而使用Junit測試框架,側是正規Android開發的必用技術,在Junit中可以得到組件,可以模擬發送事件和檢測程序處理的正確性..........

            第一步:首先在AndroidManifest.xml中加入下面代碼:

          <?xml version="1.0" encoding="utf-8"?>
          <manifest xmlns:android=http://schemas.android.com/apk/res/android
          package="hb.learn.junit"
          android:versionCode="1"
          android:versionName="1.0">
          <uses-sdk android:minSdkVersion="8" />
          <application android:icon="@drawable/icon" android:label="@string/app_name">

          <!-- 在本應用中導入需要使用的包,放在application里面activity外面 -->
          <uses-library android:name="android.test.runner" />

          <activity android:name=".JunitTestActivity"
          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>

          <!-- 記住這個一要放在application外面,不然會出現配置錯誤 信息 -->
          <instrumentation android:name="android.test.InstrumentationTestRunner"
          android:targetPackage="hb.learn.junit" android:label="Tests for My App" />
          </manifest>

            上面targetPackage指定的包要和應用的package相同。就是這個測試類所在的包名;

            第二步:編寫單元測試代碼(選擇要測試的方法,右鍵點擊“Run As”--“Android Junit Test” ):

          import android.test.AndroidTestCase;
          import android.util.Log;
          public class XMLTest extends AndroidTestCase {
          public void testSomething() throws Throwable {
          Assert.assertTrue(1 + 1 == 3);
          }
          }

          posted on 2013-08-02 11:46 順其自然EVO 閱讀(243) 評論(0)  編輯  收藏 所屬分類: android

          <2013年8月>
          28293031123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 松阳县| 泾川县| 浑源县| 都昌县| 宝坻区| 天等县| 遂宁市| 林芝县| 泉州市| 吉隆县| 渭南市| 长治县| 台中县| 平定县| 怀来县| 吴桥县| 宝坻区| 太白县| 绵阳市| 临朐县| 宣武区| 保亭| 资中县| 黄浦区| 兴安盟| 沾益县| 新建县| 五峰| 仙桃市| 定兴县| 盈江县| 新民市| 邵阳市| 且末县| 张家港市| 隆安县| 孟村| 房山区| 海盐县| 光泽县| 丰城市|