错误了java.lang.RuntimeException:存根!在Android中使用的FitNesse测试存根、错误、测试、java

2023-09-04 23:55:03 作者:执念

我试图创建使用 FitNesse的框架测试夹具,我想测试一个函数,它从服务器(RESTful服务)检索数据。我的测试用例是非常简单的:

I'm trying to create a test fixture using Fitnesse framework, and I want to test a function which retrieves data from a server (RESTFUL service). My test case is very simple:

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()); 
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(input, "iso-8859-1"), 8);
            StringBuilder content = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                content.append(line + "\n");
            }
            input.close();
            result = content.toString();
        }
        catch (Exception e) {
            Log.e(TAG + ".getJsonArrayFromUrl(String url)", "Error parsing result " + e.toString());
        }

        try {
            jsonArray = new JSONArray(result);
        }
        catch (JSONException e) {
            Log.e(TAG + "getJsonArrayFromUrl(String url)", "Error converting data " + e.toString());
        }
        return jsonArray;
    }

这里是 FitNesse的测试页:路径fitnesse.jar

And here is the Fitnesse test page:!path fitnesse.jar

!path C:\Program Files (x86)\Android\android-sdk\platforms\android-10\android.jar
!path C:\Users\chan\git\Spotr\Spotr\bin\classes

!|com.csun.spotr.fitnesse.FriendListActivityFixture|
|URL|test?|
|0|"wwa"|

由于它只是一个演示,我的测试可能看起来有点傻的时刻。不幸的是,我不断收到这些错误:

Since it's just a demo, my test might look a bit silly at the moment. Unfortunately, I keep getting these errors:

java.lang.RuntimeException: Stub!
    at android.util.Log.e(Log.java:15)
    at com.csun.spotr.util.JsonHelper.getJsonArrayFromUrl(JsonHelper.java:75)
    at com.csun.spotr.fitnesse.FriendListActivityFixture.test(FriendListActivityFixture.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at fit.TypeAdapter.invoke(TypeAdapter.java:109)
    at fit.TypeAdapter.get(TypeAdapter.java:97)
    at fit.Fixture$CellComparator.compareCellToResult(Fixture.java:371)
    at fit.Fixture$CellComparator.access$100(Fixture.java:357)
    at fit.Fixture.compareCellToResult(Fixture.java:299)
    at fit.Fixture.check(Fixture.java:295)
    at fit.ColumnFixture.check(ColumnFixture.java:51)
    at fit.Binding$QueryBinding.doCell(Binding.java:215)
    at fit.ColumnFixture.doCell(ColumnFixture.java:37)
    at fit.Fixture.doCells(Fixture.java:171)
    at fit.Fixture.doRow(Fixture.java:165)
    at fit.ColumnFixture.doRow(ColumnFixture.java:25)
    at fit.Fixture.doRows(Fixture.java:159)
    at fit.ColumnFixture.doRows(ColumnFixture.java:18)
    at fit.Fixture.doTable(Fixture.java:153)
    at fit.Fixture.interpretTables(Fixture.java:99)
    at fit.Fixture.doTables(Fixture.java:79)
    at fit.FitServer.process(FitServer.java:81)
    at fit.FitServer.run(FitServer.java:56)
    at fit.FitServer.main(FitServer.java:41)

和我不知道它是什么告诉我?我写的其他的测试方法,比如添加(),substract(),一切正常。我不知道这个错误涉及的主线程上运行一个长期的任务?你知道吗?

And I have no idea what is it telling me? I wrote other testing method like add(), substract(), everything worked fine. I wonder does this error involve running a long task on the main thread? Any idea?

推荐答案

的android.jar 只包含存根实现类。它提供了用于您的应用程序建立,一旦你有你的APK,你必须在Android设备或模拟器上运行它。

android.jar contains only stub implementation of the classes. It provides the means for you app to build, once you have your APK you must run it on an android device or emulator.

如果我没看错你尝试在主机的JVM上运行。

If I'm not wrong you are trying to run on host's JVM.