【问题标题】:Testing Google Play Service API with Robolectric使用 Robolectric 测试 Google Play 服务 API
【发布时间】:2015-01-26 01:57:34
【问题描述】:

我正在开发一个使用 Google Fit API 的应用。

我正在使用 Robolectric 进行单元测试。

我在任何地方都找不到如何模拟 Google Play API 的示例,以便 In 可以测试我的课程,而无需将实际数据写入 Fit。

【问题讨论】:

    标签: android unit-testing google-play-services robolectric google-fit


    【解决方案1】:

    这就是我们从 Robolectric 测试运行中排除 Google Analytics API 的方式。也许它也可以应用于 Google Fit API(通过将分析命名空间更改为适合命名空间)?

    public class YourTestApplication extends YourApplication
        implements TestLifecycleApplication {
    
        ...
    
        @Override
        public void beforeTest(Method method) {
            ShadowApplication shadowApplication = Robolectric.shadowOf(Robolectric.application);
            shadowApplication.declareActionUnbindable("com.google.android.gms.analytics.service.START");
        }
    
        ...
    
    }
    

    参考:http://robolectric.blogspot.sg/2013/04/the-test-lifecycle-in-20.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多