Android中使用Junit測試框架

1、首先需要在Android工程中的清單文件AndroidManifest.xml 中添加測試框架支持:

如下:

 

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.cyh.xml"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    	<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>
    <uses-sdk android:minSdkVersion="8" />
    <instrumentation android:targetPackage="com.cyh.xml" 
    android:name="android.test.InstrumentationTestRunner" />
</manifest> 

 

其中

 

<uses-library android:name="android.test.runner" />
    <instrumentation android:targetPackage="com.cyh.xml" 
    android:name="android.test.InstrumentationTestRunner" />

 

爲添加支持Junit框架測試代碼, com.cyh.xml 爲你要測試應用的包名

 

2、建立測試類,繼承自AndroidTestCase,然後測試類中書寫測試代碼,運行即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章