簡體   English   中英

Android檢測運行失敗 - 斷言錯誤

[英]Android instrumentation run failed - assertion error

我正在努力弄清楚為什么我的測試用例無法完成。 我很困惑,因為錯誤似乎只表明斷言失敗了。 這意味着測試失敗,但為什么會讓整個測試運行器崩潰?

我在控制台中看到此錯誤。

Test failed to run to completion. Reason: 'Instrumentation run failed due to 'junit.framework.AssertionFailedError''. Check device logcat for details

這是追溯:

10-27 19:51:29.006    4188-4188/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.jsonapi.sample, PID: 4188
junit.framework.AssertionFailedError
        at junit.framework.Assert.fail(Assert.java:48)
        at junit.framework.Assert.assertTrue(Assert.java:20)
        at junit.framework.Assert.assertNotNull(Assert.java:218)
        at junit.framework.Assert.assertNotNull(Assert.java:211)
        at com.example.jsonapi.JsonAPITest$2.onDone(JsonAPITest.java:101)
        at com.example.jsonapi.JsonAPITest$2.onDone(JsonAPITest.java:96)
        at org.jdeferred.impl.AbstractPromise.triggerDone(AbstractPromise.java:107)
        at org.jdeferred.impl.AbstractPromise.triggerDone(AbstractPromise.java:98)
        at org.jdeferred.impl.DeferredObject.resolve(DeferredObject.java:70)
        at com.example.jsonapi.JsonAPI$1.onResponse(JsonAPI.java:178)
        at com.example.jsonapi.JsonAPI$1.onResponse(JsonAPI.java:172)
        at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:67)
        at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
        at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5257)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

這是相應的測試:

public void testFindOneCustomURL() throws Exception {
    ArrayList<String> reqList = new ArrayList<>();
    reqList.add("queue.txt");

    MockWebServer server = getServerWithData(reqList);
    // Ask the server for its URL. You'll need this to make HTTP requests.
    URL baseUrl = server.getUrl("/api/v1");

    JsonAPI client = new JsonAPI(baseUrl, context);
    client.getGsonBuilder()
           .setDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    client.register(new VideoQueue());
    Promise prom = client.find(new VideoQueue())
            .set("user", "212139")
            .run()
            .done(new DoneCallback<ArrayList<VideoQueue>>() {
                @Override
                public void onDone(ArrayList<VideoQueue>  videoQueue) {
                    assertNotNull(videoQueue);
                    assertNotNull(videoQueue.get(0));
                    assertNotNull(videoQueue.get(0).getId());
                    assertEquals("3310190", videoQueue.get(0).getId());
                }
            }).fail(new FailCallback() {
                @Override
                public void onFail(Object rejection) {
                    assertNull(rejection);
                }
            });

    prom.waitSafely();
    // Shut down the server. Instances cannot be reused.
    server.shutdown();

    // Make sure our client hit the server
    RecordedRequest request = server.takeRequest();
    assertEquals("/api/v1/users/212139/queue", request.getPath());
}

這意味着斷言失敗了。 通常它應該報告測試用例失敗。 但是如果你把斷言放在一個回調方法中,它似乎會崩潰。 也許這是junit的錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM