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)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 离岛区| 武冈市| 贺兰县| 韶关市| 平武县| 望城县| 察雅县| 巴林右旗| 习水县| 临潭县| 咸丰县| 黔西| 山阳县| 城市| 永登县| 重庆市| 连山| 昌都县| 石景山区| 当涂县| 财经| 云南省| 邮箱| 绥江县| 滕州市| 鲜城| 浦北县| 英山县| 绥滨县| 丹寨县| 阜平县| 怀化市| 闸北区| 卓尼县| 双辽市| 万年县| 汕尾市| 游戏| 屏边| 开原市| 赣榆县|