• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    使用Junit對Android應用進行單元測試

    發布: 2010-11-03 21:03 | 作者: 廖煜嶸 | 來源: 領測軟件測試網采編 | 查看: 890次 | 進入軟件測試論壇討論

    領測軟件測試網

      在本文中,你將會學習到如何在Eclipse中創建Android JUnit的單元測試工程以及在不同的條件下創建及運行自動測試用例。

      準備工作

      本文假設讀者已經有一定的Android基礎知識,并且已經安裝了Eclipse和Android SDK等開發工具。本文將指導讀者如何將Android Junit框架應用到Android應用中去。本文還特別重點展示了如何測試Android中的Activity和如何識別程序中的錯誤。

      本文的示例代碼可以在http://code.google.com/p/simple-calc-unit-testing/中下載

      步驟1 被測試的應用SimpleCalc概況

      在本文中,將以一個寫好了的應用SimpleCalc簡單計算器為例子進行講解。這個簡單計算器有兩個功能,允許用戶輸入兩個數并將它們相加或相乘,最后顯示結果,如下圖所示:

    準備工作

      ▲

      步驟2 SimpleCalc的的界面設計

      由于應用比較簡單,只占一屏,所以我們在/res/layout/main.xml中設計如下代碼所示:

      

      

      android:orientation="vertical" android:layout_width="fill_parent"

      android:layout_height="fill_parent">

      

      android:layout_height="wrap_content" android:text="@string/hello"

      android:gravity="center_horizontal" android:textSize="48px"

      android:padding="12px" />

      

      android:hint="@string/hint1" android:inputType="numberDecimal"

      android:layout_width="fill_parent" android:textSize="48px">

      

      android:hint="@string/hint2" android:inputType="numberDecimal"

      android:layout_width="fill_parent" android:textSize="48px">

      

      android:layout_width="wrap_content" android:layout_height="wrap_content"

      android:padding="12px" android:background="#ff0000">

      

      android:layout_width="wrap_content" android:layout_height="wrap_content"

      android:orientation="horizontal" android:background="#000000"

      android:padding="4px">

      

      android:layout_height="wrap_content" android:text="@string/resultLabel"

      android:textSize="48px" android:id="@+id/resultLabel">

      

      android:layout_height="wrap_content" android:id="@+id/result"

      android:textSize="48px" android:textStyle="bold"

      android:layout_marginLeft="16px">

      

      

      

      android:layout_height="wrap_content" android:layout_width="fill_parent">

      

      

      

      

      簡單解析一下這個界面設計,我們使用了LinearLayout,以使得控件能在垂直方向豎向排列。界面中包括了顯示標題“Unit Testing Sample”的textview,兩個輸入數字的edittext控件,一個FrameLayout控件中包含了一個水平的LinearLayout,在這個LinearLayout包含了一個顯示結果的textview以及其提示文字“Result”,注意的是FrameLayout的背景顏色設置為紅色,而LinearLayou設置成了黑色背景。

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/

    TAG: junit Junit JUnit JUNIT 單元測試 應用 Android

    61/6123456>

    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備2023014753號-2
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>