qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請(qǐng)?jiān)L問 http://qaseven.github.io/

          Android:單元測(cè)試Junit的配置

           在實(shí)際開發(fā)中,開發(fā)android軟件的過程需要不斷地進(jìn)行測(cè)試。而使用Junit測(cè)試框架,側(cè)是正規(guī)Android開發(fā)的必用技術(shù),在Junit中可以得到組件,可以模擬發(fā)送事件和檢測(cè)程序處理的正確性..........

            第一步:首先在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">

          <!-- 在本應(yīng)用中導(dǎo)入需要使用的包,放在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>

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

            上面targetPackage指定的包要和應(yīng)用的package相同。就是這個(gè)測(cè)試類所在的包名;

            第二步:編寫單元測(cè)試代碼(選擇要測(cè)試的方法,右鍵點(diǎn)擊“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);
          }
          }


           在實(shí)際開發(fā)中,開發(fā)android軟件的過程需要不斷地進(jìn)行測(cè)試。而使用Junit測(cè)試框架,側(cè)是正規(guī)Android開發(fā)的必用技術(shù),在Junit中可以得到組件,可以模擬發(fā)送事件和檢測(cè)程序處理的正確性..........

            第一步:首先在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">

          <!-- 在本應(yīng)用中導(dǎo)入需要使用的包,放在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>

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

            上面targetPackage指定的包要和應(yīng)用的package相同。就是這個(gè)測(cè)試類所在的包名;

            第二步:編寫單元測(cè)試代碼(選擇要測(cè)試的方法,右鍵點(diǎn)擊“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 閱讀(244) 評(píng)論(0)  編輯  收藏 所屬分類: android

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

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 临城县| 上高县| 竹溪县| 马公市| 青川县| 景德镇市| 玉门市| 汾阳市| 康定县| 十堰市| 阜宁县| 南和县| 中阳县| 准格尔旗| 永平县| 凭祥市| 邳州市| 镇巴县| 广德县| 成都市| 尚义县| 黎城县| 灌南县| 蕲春县| 康平县| 朝阳市| 长沙市| 文昌市| 临邑县| 罗源县| 定兴县| 铜梁县| 济源市| 桃园市| 申扎县| 松桃| 揭阳市| 云和县| 遂宁市| 鄄城县| 皮山县|