繁体   English   中英

单元测试中的LowLevelHttpTransport问题

[英]Problem with LowLevelHttpTransport in unit tests

我目前正在尝试在使用HTTPtransport并且是Android应用程序一部分的类上运行一些单元测试。 google-api的文档说,这很好,因为Apache传输内置于Android中。

但是,在运行测试时,出现以下错误:

java.lang.IllegalStateException:无法在com.google.api.client.http.HttpTransport。(HttpTransport.java:156)的com.google.api.client.http.HttpTransport.useLowLevelHttpTransport(HttpTransport.java:98)处加载NetHttpTrasnport ),网址为uk.co.uk.co.redfruit.android.whogotwhat.googlebase.GoogleBaseSearch.search(GoogleBaseSearch.java:41)上的com.google.api.client.googleapis.GoogleTransport.create(GoogleTransport.java:58)。 android的android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)上的java.lang.reflect.Method.invokeNative(Native Method)上的redfruit.android.whogotwhat.test.GoogleBaseSearchTest.testSearchForBarcode(GoogleBaseSearchTest.java:22)。在android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)处进行test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)在android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.java:1447)处进行测试

这是错误吗? 还是我只是想念一些东西?

好的-我知道了问题所在。 由于您尝试确定所处环境的方式(使用class.forName()并捕获Exception),所有类路径错误都会导致此操作失败-可能会引起误解。

它正确地确定了我的环境(因此与单元测试无关),但是随后却无法加载其他一些类。

通过添加apache客户端,重新打包和转义jar,我能够解决问题。 我建议也许可以对此进行改进。

您是否可能正在使用该库的1.1版? 我刚刚修复了一个错误 ,使Apache传输在版本1.2中成为默认设置。 因此,如果您使用的是1.1版,请尝试切换到1.2,如果不能解决该错误,请让我使用。

免责声明:我是google-api-java-client库的所有者。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM