被测试类
package com.example.test;
public class ToolTest {
publicstatic int test(int a, int b) {
returna + b;
}
}
使用测试类AndroidTestCase
package com.example.test;
import android.test.AndroidTestCase;
public class MyAndroidTest extends AndroidTestCase {
publicvoid test(){
intresualt = ToolTest.test(4, 9); //被测试的工具类
assertEquals(11, resualt);
}
}
<?xml version="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<!--注意instrumentation位置,targetPackage路径为要测试的的方法所在的包名-->
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.test"
></instrumentation>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!--注意uses-library位置-->
<uses-libraryandroid:name="android.test.runner"/>
<activity
android:name="com.example.test.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<actionandroid:name="android.intent.action.MAIN" />
<categoryandroid:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>