Robolectric和chrisbanes / ActionBar-PullToRefresh活动测试

时间:2014-04-17 16:33:02

标签: android robolectric pull-to-refresh

我试图在使用AppCompat和chrisbanes / ActionBar-PullToRefresh库的活动上使用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)

这是我的setup配置:

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

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

谢谢,

1 个答案:

答案 0 :(得分:1)

请参阅此处的回复: https://github.com/robolectric/robolectric/issues/1041

更改拉动以刷新从onCreate到onStart或onViewCreated(对于片段)的初始化。为我工作。