亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
Android下Junit測試框架配置
作者:網絡轉載 發布時間:[ 2016/3/18 11:41:56 ] 推薦標簽:單元測試工具 軟件測試

  我們的業務代碼一般是放在一個新的包下面,這個業務類不能夠通過右鍵run as java application,因為android項目只能運行在手機上的dalvak虛擬機里面。
  新建一個包,里面寫測試類,測試類需要繼承AndroidTestCase類,寫測試方法,需要throws exception拋出異常給測試框架,測試方法里面一般new出需測試的類,調用它的方法,然后斷言結果,assertEquals(預估, 實際結果)
  在outline視窗 (window=>show view=>outline)里面選中該方法右鍵run as android junit test
  此時會報錯
  [2016-02-27 21:29:54 - 單元測試] 單元測試 does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library android.test.runner in its AndroidManifest.xml
  需要在清單文件里面配置instrumentation指令集
<!-- 指令集在manifest節點下 -->
<!-- 測試用例,名稱是固定的,目標包名 -->
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.tsh.junit" >
</instrumentation>
<!-- 使用的函數庫,在application節點下 -->
<uses-library android:name="android.test.runner"/>
  Xml里面寫注釋 ctrl+shift+/,
  Junit里面打印出綠條,說明沒有錯誤,如果有錯誤打印紅色的條,錯誤追逐里面有錯誤信息,如斷言錯誤等,如果清單文件里面的信息記不住,那么請這樣操作,new => project =>android android test project => select test target 完成以后會有個項目里面有清單文件
  java代碼:
package com.tsh.junit.test;
import com.tsh.junit.service.CalcService;
import android.test.AndroidTestCase;
public class CalServiceTest extends AndroidTestCase {
public void testAdd() throws Exception{
CalcService service=new CalcService();
int res=service.add(3, 5);
assertEquals(8, res);
}
}
  清單文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tsh.junit"
android:versionCode="1"
android:versionName="1.0" >
<!-- 指令集在manifest節點下 -->
<!-- 測試用例,名稱是固定的,目標包名 -->
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.tsh.junit" >
</instrumentation>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="23" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- 使用的函數庫,在application節點下 -->
<uses-library android:name="android.test.runner"/>
<activity
android:name=".MainActivity"
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>
</manifest>

軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 国产亚洲欧美久久久久 | 三级亚洲 | 欧美一级二级三级视频 | 欧美久久综合 | 波兰性xxxxx极品hd | 视频一本大道香蕉久在线播放 | 日本乱人伦片中文字幕三区 | 波多野结衣在线不卡 | 日日摸夜夜添夜夜添特色大片 | 在线播放一区二区三区 | 成人欧美网站 | 欧美日日 | 婷婷中文字幕 | 最新一本大道香蕉综合 | 成人亚洲欧美日韩在线观看 | 日韩在线你懂的 | 成人看免费一级毛片 | 亚洲男女一区二区三区出奶水了 | 欧美韩日在线 | 国产精品午夜久久 | 国产一区二区三区在线观看精品 | 在线日本三级 | 免费成人黄色 | 欧美成人免费高清网站 | m3u8久久国产精品影院 | 日韩在线视频不卡一区二区三区 | 天天射天天射 | 一卡二卡3卡四卡网站精品国 | 国产成人在线视频 | 国产剧情乱偷 | 久久99国产亚洲精品观看 | 亚洲国产精品毛片∧v卡在线 | 日本三级网 | 亚洲高清成人欧美动作片 | 欧美激情在线观看一区二区三区 | 九九热久久免费视频 | 黄色毛片免费在线观看 | 欧美大黄视频 | 又爽又大又光又色的午夜视频 | 国产男女猛烈无遮挡 | 日本 国产 欧美 |