Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

CountingTaskExecutorRule

open class CountingTaskExecutorRule : TestWatcher
androidx.arch.core.executor.testing.CountingTaskExecutorRule

A JUnit Test Rule that swaps the background executor used by the Architecture Components with a different one which counts the tasks as they are start and finish.

You can use this rule for your host side tests that use Architecture Components.

Summary

Public constructors

A JUnit Test Rule that swaps the background executor used by the Architecture Components with a different one which counts the tasks as they are start and finish.

Public methods
open Unit
drainTasks(time: Int, timeUnit: TimeUnit!)

Waits until all active tasks are finished.

open Boolean

Returns false if there are tasks waiting to be executed, true otherwise.

Protected methods
open Unit
finished(description: Description!)

open Unit

Called when the number of awaiting tasks reaches to 0.

open Unit
starting(description: Description!)

Public constructors

<init>

CountingTaskExecutorRule()

A JUnit Test Rule that swaps the background executor used by the Architecture Components with a different one which counts the tasks as they are start and finish.

You can use this rule for your host side tests that use Architecture Components.

Public methods

drainTasks

open fun drainTasks(time: Int, timeUnit: TimeUnit!): Unit

Waits until all active tasks are finished.

Parameters
time Int: The duration to wait
timeUnit Int: The time unit for the time parameter
Exceptions
InterruptedException If thread is interrupted while waiting
TimeoutException If tasks cannot be drained at the given time

isIdle

open fun isIdle(): Boolean

Returns false if there are tasks waiting to be executed, true otherwise.

Return
Boolean: False if there are tasks waiting to be executed, true otherwise.

See Also

Protected methods

finished

protected open fun finished(description: Description!): Unit

onIdle

protected open fun onIdle(): Unit

Called when the number of awaiting tasks reaches to 0.

See Also

starting

protected open fun starting(description: Description!): Unit