您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源單元測(cè)試工具 > junit
Android搭建Junit測(cè)環(huán)境
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2016/4/19 10:45:22 ] 推薦標(biāo)簽:單元測(cè)試 Android

  在AndroidManifest.xml文件中增加兩個(gè)東西,分別是:
  1、uses-library ,位于application里面。
  2、instrumentation,與application同級(jí)。
  完整的AndroidManifest.xml文件如下:
1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3       package="com.lzb.study.db"
4       android:versionCode="1"
5       android:versionName="1.0">
6     <application android:icon="@drawable/icon" android:label="@string/app_name">
7         <!-- 單元測(cè)試 -->
8         <uses-library android:name="android.test.runner" />
9         <activity android:name=".DBActivity"
10                   android:label="@string/app_name">
11             <intent-filter>
12                 <action android:name="android.intent.action.MAIN" />
13                 <category android:name="android.intent.category.LAUNCHER" />
14             </intent-filter>
15         </activity>
16
17     </application>
18
19     <!-- 啟動(dòng)測(cè)試器 -->
20     <instrumentation android:name="android.test.InstrumentationTestRunner"
21         android:targetPackage="com.lzb.study.db" android:label = "Tests for My App" />
22
23 </manifest>
  然后,建立測(cè)試類(lèi)。測(cè)試類(lèi)中的測(cè)試方法必須以test開(kāi)頭。
1 public class PersonServiceTest extends AndroidTestCase {
2
3     public void testSave() throws Exception {
4         PersonService ps = new PersonService(this.getContext());
5         Person person = new Person();
6         person.setName("李剛");
7         person.setAge((short)0);
8         ps.save(person);
9
10     }
11 }
  然后在test類(lèi)中,選中testcase,點(diǎn)擊右鍵,選擇Run As --> Android Junit Test,開(kāi)始執(zhí)行case。

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd