新建Test Class类 extends 继承 AndroidTestCase
在AndroidManifest.xml
<Application>外面添加
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="填写package名" />
即如下AndroidManifest.xml package 右边参数com.chen.android_petlove
package="com.chen.android_petlove"
package com.chen.android_petlove.test;
import java.util.ArrayList;
import com.chen.android_petlove.form.Comment;
import com.chen.android_petlove.form.Discuz;
import com.chen.android_petlove.query.Quer;
import com.chen.android_petlove.register.Regist;
import com.chen.android_petlove.signin.SignIn;
import android.test.AndroidTestCase;
public class TestCase extends AndroidTestCase{
public void Register()throws Exception{
Regist r = new Regist(getContext(), "12345", "password", "MyName", 11, "4040390@qq.com", "广州大学", "13800138000");
r.Commit();
}
public void Login()throws Exception{
SignIn si = new SignIn(getContext(), "12345", "12345");
si.Commit();
}
public void getPost()throws Exception{
ArrayList<Discuz> listDiscuz = new ArrayList<Discuz>();
Quer q = new Quer(getContext());
q.getAllPost(listDiscuz, 20, 0);
}
public void getComment()throws Exception{
ArrayList<Comment> listComment = new ArrayList<Comment>();
Quer q = new Quer(getContext());
q.getAllComment("", listComment, 20, 0);
}
}
选中方法名 右键 RunAs-->Android Junit Test
等待测试完成