using robolectric version 4.5.1
What is the difference between
shadowOf(getMainLooper()).idleFor(1, TimeUnit.MILLISECONDS);
and
shadowOf(getMainLooper()).idle();
shadowOf(getMainLooper()).idle(); is causing my test case to fail giving following exception message
Main looper has queued unexecuted runnables. This might be the cause of the test
failure. You might need a shadowOf(getMainLooper()).idle() call.
java.lang.Exception: Main looper has queued unexecuted runnables. This might be the cause of the test failure. You might need a shadowOf(getMainLooper()).idle() call.
at org.robolectric.android.internal.AndroidTestEnvironment.checkStateAfterTestFailure(AndroidTestEnvironment.java:502)
at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:581)
at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:278)
at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
But shadowOf(getMainLooper()).idleFor(1, TimeUnit.MILLISECONDS); this works fine how?
as documentation idleFor Advances the system clock by the given time, then executes all posted tasks scheduled before or at the given time. What it means Advances the system clock? How my test is getting passed on using idleFor() instead of idle()
from Android test cases robolectric Shadowlooper idle VS idleFor
No comments:
Post a Comment