Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 中 JUnit 測試的配置要點

編輯:Android 開發教學

在 Android 專案中使用 JUnit 測試,需要在 AndroidManifest.xml 中正確設定測試執行器與函式庫。

必要設定

在 application 內加入 uses-library 指向 android.test.runner,並在 manifest 中加入 instrumentation,指定 InstrumentationTestRunner 與 targetPackage。targetPackage 必須與被測試應用的套件名稱一致。

執行測試

建立繼承自 AndroidTestCase 的測試類別,撰寫測試方法後,選擇 Run As Android JUnit Test。若出現找不到 InstrumentationTestRunner 的錯誤,通常表示上述設定缺少或位置錯誤。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved