这个问题专门针对Flurry,但我很好奇如何为任何第三方语言做这件事。
基本上,Flurry在Robolectric中导致崩溃(根据:https://github.com/robolectric/robolectric-gradle-plugin/issues/144),我可以让我的单元测试工作的唯一方法是删除对Flurry的所有调用(例如FlurryAgent.init,FlurryAgent.onStartSession等等......)。
没有将所有这些放在BuildConfig.Debug'如果'块(这意味着有很多),有没有办法全局导致所有对FlurryAgent的调用在调试模式下编译为无操作,例如?
LeakCanary是我希望看到的效果的一个很好的例子。
dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
}
答案 0 :(得分:2)
我们也在使用Flurry。因此,对于应用程序的其余部分,我们的class User < ActiveRecord::Base
has_one :user_detail, :dependent => :destroy
has_one :role, :through => :user_detail
end
class UserDetail < ActiveRecord::Base
belongs_to :user
has_one :role
end
class Role < ActiveRecord::Base
belongs_to :user_detail
end
类隐藏了Flurry,这有助于我们轻松地模拟它并验证与它的交互。
要测试Analytics
本身,我们使用其他技术:
Analytics
测试:
public class Analytics {
...
protected startFlurry(Context context, String apiKey) {
FlurryAgent.onStartSession(context, apiKey);
}
...
}
这是解决方法,但我现在没有更好的解决方案。