我刚刚开始使用Robolectric,想知道如何解决Google Play服务.我正在使用Robolectric 3 RC2,而我的成绩如下:
build.bradle
compile 'com.squareup.okhttp:okhttp:2.3.0'compile 'com.Google.androID.gms:play-services:7.0.0'testCompile ("org.robolectric:robolectric:3.0-rc2"){ exclude module: 'commons-logging' exclude module: 'httpclIEnt'}testCompile ("org.robolectric:shadows-play-services:3.0-rc2"){ exclude module: 'commons-logging' exclude module: 'httpclIEnt'}testCompile 'com.squareup.okhttp:mockwebserver:1.2.1'
我正在从项目中运行一种方法,以从API获取Json.调用时,我会传递广告ID:
AdvertisingIDClIEnt.Info adInfo = null; try { adInfo = AdvertisingIDClIEnt.getAdvertisingIDInfo(mContext); } catch (IOException | GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingID). e.printstacktrace(); }
我测试的主要部分是:
@Test(timeout = 7000)public voID JsonLoading() { try { clIEnt.loadData(this); } catch (Exception e){ ex = e; } assertNull(ex); //wait for task code ShadowApplication.runBackgroundTasks();
每次运行测试时,我都会收到GooglePlayServicesNotAvailableException(来自e.printstacktrace();),并且无法解决它并断言它,因此测试将无法通过.
我还没有找到调试我的代码的任何线索.
解决方法:
前几天我碰到了这个.
采用:
testCompile 'org.robolectric:shadows-play-services:3.0'testCompile 'org.robolectric:shadows-support-v4:3.0'
并查看以下示例:
public class TestBase { @Before public voID setUp() throws Exception { // Turn off Google Analytics - Does not need to work anymore final ShadowApplication shadowApplication = Shadows.shadowOf(RuntimeEnvironment.application); shadowApplication.declareActionUnbindable("com.Google.androID.gms.analytics.service.START"); // Force success ShadowGooglePlayServicesUtil.setIsGooglePlayServicesAvailable(ConnectionResult.SUCCESS); } @After public voID tearDown() throws Exception { }}public MyTestClass extends TestBase {}
总结 以上是内存溢出为你收集整理的android-Robolectric 3 GooglePlayServicesNotAvailableException全部内容,希望文章能够帮你解决android-Robolectric 3 GooglePlayServicesNotAvailableException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)