1.在Eclipse的菜单中依次点击File-new-Project
2.然后选择Android Test Project
3.填入项目名字,选择为哪一个项目创建单元测试,然后就OK了
4.编写测试用例
新建的类继承与AndroidTestCase 就可以编写测试类了
例:
public class StatusTest extends AndroidTestCase { public static final String TAG = "StatusTest"; /** * 登陆授权测试 * @throws Exception */ public void testLogin() throws Exception { System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY); System.setProperty("weibo4j.oauth.consumerSecret",Weibo.CONSUMER_SECRET); String oauth_pin = null ; boolean loginResult = false ; //0.实例化Weibo Weibo weibo = OAuthConstant.getInstance().getWeibo(); //1.从新浪获取RequestToken。 RequestToken requestToken = weibo.getOAuthRequestToken(); // 2.通过授权地址获得oauth_verifier授权码 oauth_pin = OAuthConstant.getInstance().getWeibo().getOAuthPin("levelup_loving@sina.com", "xxxxxx", requestToken.getToken()); // 3.RequestToken通过返回的授权码获取AccessToken AccessToken accessToken = requestToken.getAccessToken(oauth_pin); // 4.给微博设置accessToken和accesssSecret weibo.setToken(accessToken.getToken(), accessToken.getTokenSecret()); // 5.验证用户合法性 weibo.verifyCredentials(); // 6.登录成功 loginResult = true; // 7.保存AccessToken等相关参数 OAuthConstant.getInstance().setAccessToken(accessToken); OAuthConstant.getInstance().setRequestToken(requestToken); Log.d(TAG, "accessToken="+accessToken.getToken()+",TokenSecret="+accessToken.getTokenSecret()); } }