"存根&#34!;使用Robolectric模拟HTTP请求时出错

时间:2014-03-19 14:46:07

标签: android maven robolectric android-testing androidhttpclient

我有一个用@RunWith(RobolectricTestRunner.class)注释的测试类。

以下行中的所有测试都失败:Robolectric.addPendingHttpResponse(200, " ... ");

这就是失败的样子:

java.lang.RuntimeException: Stub!
 at org.apache.http.params.AbstractHttpParams.<init>(AbstractHttpParams.java:5)
 at org.apache.http.params.BasicHttpParams.<init>(BasicHttpParams.java:6)
 at org.robolectric.tester.org.apache.http.TestHttpResponse.<init>(TestHttpResponse.java:30)
 at org.robolectric.tester.org.apache.http.TestHttpResponse.<init>(TestHttpResponse.java:43)
 at org.robolectric.tester.org.apache.http.FakeHttpLayer.addPendingHttpResponse(FakeHttpLayer.java:47)
 at org.robolectric.Robolectric.addPendingHttpResponse(Robolectric.java:1056)
 at [my method]
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
 at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:175)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
 at org.junit.runners.Suite.runChild(Suite.java:128)
 at org.junit.runners.Suite.runChild(Suite.java:24)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
 at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
 at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
 at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

除了HTTP请求伪造之外,Robolectric的其他功能还有 no 问题。我正在使用Maven。有什么想法吗?

0 个答案:

没有答案