1.继承AndroidTestCase :public class JunitTest3 extends AndroidTestCase {}
2.在AndroidManifest.xml清单文件中添加如下代码:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.showdata"
android:versionCode="1"
android:versionName="1.0" >
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.showdata" >
</instrumentation>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="android.test.runner"/>
<activity
android:name="com.example.showdata.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>
3.在要测试的方法上右击-->Run As --->Android Junit Test、需要先打开模拟器