在實(shí)際開(kāi)發(fā)中,開(kāi)發(fā)android軟件的過(guò)程需要不斷地進(jìn)行測(cè)試。而使用Junit測(cè)試框架,側(cè)是正規(guī)Android開(kāi)發(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è)試類(lèi)所在的包名;
第二步:編寫(xiě)單元測(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í)際開(kāi)發(fā)中,開(kāi)發(fā)android軟件的過(guò)程需要不斷地進(jìn)行測(cè)試。而使用Junit測(cè)試框架,側(cè)是正規(guī)Android開(kāi)發(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è)試類(lèi)所在的包名; 第二步:編寫(xiě)單元測(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); } } |
|