如何在Android工作室中测试Volley Library?

I l*_*ing 6 java junit android android-volley

我想使用Volley Library将JSON文件从Android应用程序发送到REST API服务器.首先,我想用JUnit Tests测试库,看看我的请求是否正确发送,而不是在应用程序中运行它们.这是我的测试:

public class NetworkCommunicationTest extends AndroidTestCase {

    private static final String JSON_URL = "https://www.example.com/data.json";
    Context context;

    @Test
    public void testSendGet() {

        context = new MockContext();

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,JSON_URL, null, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
             Assert.assertTrue("",true);

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                // TODO Auto-generated method stub

            }
        });

        RequestQueue requestQueue = Volley.newRequestQueue(context);
        requestQueue.add(jsonObjectRequest);
    }

}
Run Code Online (Sandbox Code Playgroud)

我已将此添加到Android Studio项目中,但我收到此错误:

java.lang.NullPointerException
at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:48)
at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:78)
at tests.NetworkCommunicationTest.testSendPost(NetworkCommunicationTest.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能解决这个问题?如何打印response.toString()消息?

只是为了更多的额外参考,没有我链接的库,我得到了isLoggable问题.