android - Robolectric 和 chrisbanes/ActionBar-PullToRefresh Activity 测试

标签 android robolectric pull-to-refresh

我正在尝试在使用 AppCompat 和 chrisbanes/ActionBar-PullToRefresh 库的 Activity 上使用 Robolectric(2.3-20140416.035220-155) 实现一些 TDD。

然而,我收到以下错误:

java.lang.StackOverflowError
    at java.security.AccessController.doPrivileged(Native Method)
    at org.fest.reflect.util.Accessibles.setAccessible(Accessibles.java:57)
    at org.fest.reflect.util.Accessibles.setAccessibleIgnoringExceptions(Accessibles.java:36)
    at org.fest.reflect.method.Invoker.invoke(Invoker.java:118)
    at org.robolectric.bytecode.ShadowWrangler.shadowOf(ShadowWrangler.java:434)
    at org.robolectric.Robolectric.shadowOf_(Robolectric.java:1027)
    at org.robolectric.Robolectric.shadowOf(Robolectric.java:457)
    at org.robolectric.Robolectric.getShadowApplication(Robolectric.java:1259)
    at org.robolectric.shadows.ShadowLooper.getMainLooper(ShadowLooper.java:59)
    at android.os.Looper.getMainLooper(Looper.java)
    at org.robolectric.Robolectric.getUiThreadScheduler(Robolectric.java:1251)
    at org.robolectric.shadows.ShadowView.post(ShadowView.java:318)
    at android.view.View.post(View.java)

并且以下行在堆栈跟踪中重复:

    at uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher$2.run(PullToRefreshAttacher.java:131)
    at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:37)
    at org.robolectric.util.Scheduler.post(Scheduler.java:42)
    at org.robolectric.shadows.ShadowView.post(ShadowView.java:318)
    at android.view.View.post(View.java)

这是我的设置配置:

@Before
public void setup() {
    activity = Robolectric.buildActivity(MainActivity.class).create().visible().start().resume().get();
}

是否有任何我必须添加的特殊配置,或者只是 Robolectric 目前与 chrisbanes 库不兼容?

谢谢,

最佳答案

请看这里的回复: https://github.com/robolectric/robolectric/issues/1041

将您的拉取刷新初始化从 onCreate 更改为 onStart 或 onViewCreated(对于 fragment )。为我工作。

关于android - Robolectric 和 chrisbanes/ActionBar-PullToRefresh Activity 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23138698/

相关文章:

Android ..当我沿着适配器向下滚动时ListView崩溃..

java - 如何在 robolectric 测试中添加一些一次性启动代码

android - ScrollView中的WebView在向上滑动时调用refreshControl React Native Android一直

java - 让应用程序在 Android 上始终在后台运行

android - 启动模拟器时如何修复 GRPC 错误 “WARNING: EmulatorService.cpp:448: Cannot find certfile”?

android - 使用 adb 启动 Activity

android - 在 Android studio gradle 中我可以同时使用 Robolectric 和 Android instrumentation 吗?

android - 为什么此测试会触发 Robolectric Delegate runner RuntimeException?

android - Chris Banes 拉动刷新 Fragment 中的 ListView/GridView

android - DragSortListView 无法在 SwipeRefreshLayout 上向下拖动