Robolectric (3.1) should be able to execute runnable posted to the handler.
@Test
public void shouldExecuteRunnable() throws Exception {
final CountDownLatch signal = new CountDownLatch(1);
final boolean[] result = {false};
Runnable runnable = new Runnable() {
@Override
public void run() {
result[0] = true;
signal.countDown();
}
};
HandlerThread handlerThread = new HandlerThread("HandlerThread");
handlerThread.start();
Handler handler = new Handler(handlerThread.getLooper());
handler.post(runnable);
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
signal.await(5, TimeUnit.SECONDS);
Assert.assertTrue(result[0]);
}
Test fails on assertion. Am I missing something?
Any help will be appreciated.
Aucun commentaire:
Enregistrer un commentaire