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

  在AndroidManifest.xml文件中增加兩個東西,分別是:
  1、uses-library ,位于application里面。
  2、instrumentation,與application同級。
  完整的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         <!-- 單元測試 -->
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     <!-- 啟動測試器 -->
20     <instrumentation android:name="android.test.InstrumentationTestRunner"
21         android:targetPackage="com.lzb.study.db" android:label = "Tests for My App" />
22
23 </manifest>
  然后,建立測試類。測試類中的測試方法必須以test開頭。
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類中,選中testcase,點擊右鍵,選擇Run As --> Android Junit Test,開始執(zhí)行case。

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