我正在尝试使用Fitnesse框架创建一个测试夹具,我想测试一个从服务器检索数据的函数(RESTFUL服务).我的测试用例非常简单:
public class FriendListActivityFixture extends ColumnFixture {
public int URL;
public String test() {
JSONArray array = JsonHelper.getJsonArrayFromUrl("http://107.22.209.62/android/get_users.php");
return array.toString();
}
}
public static JSONArray getJsonArrayFromUrl(String url) {
InputStream input = null;
String result = "";
JSONArray jsonArray = null;
try {
HttpClient httpclient = CustomHttpClient.getHttpClient();
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
input = entity.getContent();
}
catch (Exception e) {
Log.e(TAG + ".getJsonArrayFromUrl(String url)", "Error in http connection " + e.toString()); …Run Code Online (Sandbox Code Playgroud)