您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源單元測(cè)試工具 > junit
Android 下junit 單元測(cè)試
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/1/14 14:47:00 ] 推薦標(biāo)簽:單元測(cè)試 junit Android

  接下來(lái)是程序的Manifest:

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

<?xml version="1.0" encoding="utf-8"?>

<manifestxmlns:android="http://schemas.android.com/apk/res/android"

package="com.android.testapp"

android:versionCode="1"

android:versionName="1.0.0">

<applicationandroid:icon="@drawable/icon"android:label="@string/app_name">

<activityandroid:name=".MainActivity"

android:label="@string/app_name">

<intent-filter>

<actionandroid:name="android.intent.action.MAIN"/>

<categoryandroid:name="android.intent.category.LAUNCHER"/>

</intent-filter>

</activity>

<uses-libraryandroid:name="android.test.runner"/>

</application>

<instrumentationandroid:targetPackage="com.android.testapp"android:name="android.test.InstrumentationTestRunner"android:label="Test Unit Tests"></instrumentation>

</manifest>

  在這個(gè)文件中,我將 Activity和Instrumentation的聲明寫(xiě)到了一起,而沒(méi)有像Apis Demo那樣分開(kāi)。請(qǐng)注意里面的標(biāo)簽。如果沒(méi)有那句,在運(yùn)行測(cè)試時(shí)會(huì)報(bào)告找不到TestRunner。這是由于 Android在build的時(shí)候只把需要的東西打包,所以你必須明確的告訴Android Builder這一點(diǎn)。

wordend 相關(guān)閱讀:

    MOTODEV初體驗(yàn),高效Android開(kāi)發(fā)工具
    詳解如何實(shí)現(xiàn)一個(gè)基本的Android用戶界面
    Android應(yīng)用開(kāi)發(fā)實(shí)戰(zhàn):GPS與加速度傳感器

  3、Build和Install

  在 Eclipse上,這兩個(gè)步驟是一起完成的。只要點(diǎn)一下Run即可。只不過(guò)如果你不在Run Configuration里將安裝后的Launch Action設(shè)為“Do Nothing”,會(huì)自動(dòng)運(yùn)行一下你的MainActivity。對(duì)于我們,設(shè)為Do Nothing即可。如下圖:

 

  完成后,利用命令:

  adb shell pm list packages

  可以在已經(jīng)安裝的pkg列表里看到com.android.testapp。

  4、運(yùn)行測(cè)試,查看結(jié)果

  之后打開(kāi)命令行,運(yùn)行以下命令

  adb shell am instrument –e class com.android.testapp.test.TestMainActivity –w com.android.testapp/android.test.InstrumentationTestRunner

  即可看到如下的結(jié)果:

  可以看到,單元測(cè)試正確的找到了減法中的錯(cuò)誤。結(jié)果中的成功的測(cè)試顯示為”.”,一個(gè)失敗的顯示為”F”。只不過(guò)我還是不太理解為什么我只寫(xiě)了兩個(gè)測(cè)試方法,Tests run卻顯示了3。

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