1、在AndroidMenifest.xml配置文件中增加以下配置信息:
package="com.cjm.android.test"
android:versionCode="1"
android:versionName="1.0">
......
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.cjm.android.test"/>
2、新建单元测试类,该类需要继承AndroidTestCase类。这个类本身是继承junit.framework.TestCase,并提供了getContext()方法,用于获取Android上下文环境。
public class HttpTest extends AndroidTestCase {
String url = "http://10.173.78.30:7777/android_web/testServlet";
public void testGet() throws Exception {
String result = HttpClientUtils.handlerGet(url);
printResult(result);
}
public void testPost() throws Exception {
String result = HttpClientUtils.handlerPost(url);
printResult(result);
}
}