Android 对施用进行单元测试

Android 对应用进行单元测试

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="org.soai.app"

    android:versionCode="1"

    android:versionName="1.0" >


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


    <application

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name" >

        <activity

            android:label="@string/app_name"

            android:name=".MainActivity" >

            <intent-filter >

                <action android:name="android.intent.action.MAIN" />


                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        

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

    </application>

 <instrumentation android:name="android.text.InstrumentationTestRunner"

 android:targetPackage="org.soai.app" android:label="Tests for My app"/>

</manifest>



 

测试类:需要继承AndroidTestCase类

public class FileServiceTest extends AndroidTestCase {

     private static final String TAG = "FileServiceTest";

     public void testRead() throws Throwable{

     FileService service = new FileService(this.getContext());

     String result = service.read("test.txt");

     Log.i(TAG, result);

     } 

}