CountingTaskExecutorRule

public class CountingTaskExecutorRule
extends TestWatcher

java.lang.Object
   ↳ org.junit.rules.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

CountingTaskExecutorRule()

Public methods

void drainTasks(int time, TimeUnit timeUnit)

Waits until all active tasks are finished.

boolean isIdle()

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

Protected methods

void finished(Description description)
void onIdle()

Called when the number of awaiting tasks reaches to 0.

void starting(Description description)

Inherited methods

Public constructors

CountingTaskExecutorRule

public CountingTaskExecutorRule ()

Public methods

drainTasks

public void drainTasks (int time, 
                TimeUnit timeUnit)

Waits until all active tasks are finished.

Parameters
time int: The duration to wait

timeUnit TimeUnit: The time unit for the time parameter

Throws
InterruptedException If thread is interrupted while waiting
TimeoutException If tasks cannot be drained at the given time

isIdle

public boolean isIdle ()

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

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

See also:

Protected methods

finished

protected void finished (Description description)

Parameters
description Description

onIdle

protected void onIdle ()

Called when the number of awaiting tasks reaches to 0.

See also:

starting

protected void starting (Description description)

Parameters
description Description