3
我无法获得robolectric(1.1版)测试用例中的主UI线程。该应用程序的方法,我的测试中有以下检查:使用robolectric访问UI线程
if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
throw new IllegalStateException(
"This method should be called from the Main UI Thread");
}
}
以下列方式调用时,该检查将失败:
@Test
public void maTest() {
Runnable task = new Runnable() {
@Override
public void run() {
adapter.testThreadPrecondition();
}
};
new Handler(Looper.getMainLooper()).post(task);
}
也试过“runOnUiThread”,并得到了同样的检查失败。到底是怎么回事?不同的主弯?
用的AsyncTask也试过,但里面什么也没有“onPostExecute”似乎被调用(或者被调用只是默默地失败) task.execute(); Robolectric.getBackgroundScheduler()。runOneTask(); Robolectric.getUiThreadScheduler()。runOneTask(); – chris
曾经找到过这个解决方案? – theV0ID
可悲的是,我取消了测试。 – chris