<instrumentation android:name="android.test.InstrumentationTestRunner"
targetPackage="项目包名"></instrumentation>
2.和Activity同级的
<uses-library android:name="android.test.runner"/>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xing.danyuces"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="xing.danyuces"></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="xing.danyuces.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>
</manifest>
3.创建test测试包
创建类继承AndroidTestCase
public class Test extends AndroidTestCase {
public void test(){
Log.i("Tog", "单元测试");
}
public void test2(){
Button but=new Button(getContext());
MainActivity main=new MainActivity();
main.onClick(but);
assertEquals(1, 1);
}
}
4.断言
assertEquals();
注:运行时直接运行方法就行