user2583621
user2583621

Reputation: 165

unit test delayed block of Android app with Robolectric

I want to test execution of a block scheduled with View#postDelayed(Runnable, delay). So before asserting I call Robolectric.runUiThreadTasksIncludingDelayedTasks(). But there the test code gets stuck, i.e. does not return.

I am sure that that delayed block is called if I run the app directly.

Is this a bug of the runUiThreadTasksIncludingDelayedTasks() or are there any other preconditions to use it?

Thx, Mick

Upvotes: 2

Views: 1300

Answers (2)

pbm
pbm

Reputation: 5371

With Robolectric 3.8 you can use:

Robolectric.flushForegroundThreadScheduler()

This executes all runnables that have been enqueued on the foreground scheduler.

Upvotes: 1

user2583621
user2583621

Reputation: 165

Works with latest release version of Robolectric.

Upvotes: 0

Related Questions