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

Android 測試框架 AndroidTestCase 的使用方法

編輯:關於 Android 程式設計

在 Android 中使用測試框架,關鍵步驟主要有兩個。

一、測試類別繼承 AndroidTestCase

讓你的測試類別繼承 AndroidTestCase,並以 test 開頭的方法撰寫測試案例:

package com.njupt.junittest;

import android.test.AndroidTestCase;

public class MyTest extends AndroidTestCase {
    public void test1() {
        System.out.println("我愛章澤天...");
    }
}

二、在 AndroidManifest.xml 中進行配置

需要在 manifest 節點下配置 instrumentation,並在 application 節點下配置 uses-library:




    

    

    

    
        
    

完成這兩個步驟後,即可透過 InstrumentationTestRunner 執行測試,驗證應用程式的行為是否符合預期。

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