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