qileilove

          blog已經(jīng)轉移至github,大家請訪問 http://qaseven.github.io/

          Android 單元測試用法 簡介

          本代碼中只簡單寫了一個類,可以在該類中增加想要測試的功能項。

          Focus2AndroidTest測試類
          package com.example.aaaaa;
          import android.test.AndroidTestCase;
          public class Focus2AndroidTest extends AndroidTestCase {
          @Override
          protected void setUp() throws Exception {
          // TODO Auto-generated method stub
          super.setUp();
          System.out.println("====aaaa====");
          }
          }

            AndroidManifest.xml中需要增加幾個屬性

          <?xml version="1.0" encoding="utf-8"?>
          <manifest xmlns:android=http://schemas.android.com/apk/res/android
          package="com.example.aaaaa"
          android:versionCode="1"
          android:versionName="1.0" >
          <uses-sdk
          android:minSdkVersion="7"
          android:targetSdkVersion="7" />
          <application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" >
          <activity
          android:name="com.example.aaaaa.Focus2AndroidTest"
          android:label="@string/app_name" >
          <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
          </activity>
          <uses-library android:name="android.test.runner" />//增加的第一個位置
          </application>
          <uses-permission android:name="android.permission.RUN_INSTRUMENTATION" />//增加的第二個位置
          <instrumentation
          android:name="android.test.InstrumentationTestRunner"
          android:label="Test for my app"
          android:targetPackage="com.example.aaaaa" />
          </manifest>

            運行程序時與正常的運行部太一樣。右鍵功工程名->run as->android jUnit test即可看到運行結果。

            注意包名等地方要與當前工程名相一致。

            運行結果:(右側的東西為正常運行后的內容)

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

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

          導航

          統(tǒng)計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 蓬安县| 霞浦县| 当涂县| 清镇市| 南华县| 肃北| 五原县| 枝江市| 昌黎县| 南乐县| 寿光市| 庆云县| 驻马店市| 兰坪| 锡林浩特市| 岳阳市| 石阡县| 得荣县| 光山县| 通化县| 吕梁市| 清镇市| 宜春市| 府谷县| 尉氏县| 都安| 郧西县| 秀山| 建阳市| 新龙县| 湖北省| 岳池县| 海盐县| 香格里拉县| 翁牛特旗| 江津市| 溆浦县| 靖西县| 元氏县| 阿巴嘎旗| 松原市|