android单元测试

每次调试android程序都需要启动模拟器,甚是麻烦。今天发现android中也是有testcase的。代码如下:

HelloCase类

import android.test.AndroidTestCase;
import android.util.Log;

public class HelloCase extends AndroidTestCase {

    public static void testHello(){
        Log.i("hello","testCaSe");
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.water.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
           <uses-library android:name="android.test.runner" />
        <activity
            android:name=".TestAndCaseActivity"
            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>
<instrumentation android:name="android.test.InstrumentationTestRunner"  
      android:targetPackage="com.water.test" android:label="Tests for My App" />  
</manifest>

 

引用的runner包和权限

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

<instrumentation android:name="android.test.InstrumentationTestRunner" 
      android:targetPackage
="com.water.test" android:label="Tests for My App" />

 

posted @ 2012-11-03 11:06  清水居士  阅读(240)  评论(0编辑  收藏  举报