public interface

TestDriver

 androidx.work.testing.TestDriver

Gradle dependencies

compile group: 'androidx.work', name: 'work-testing', version: '2.8.0-alpha02'

  • groupId: androidx.work
  • artifactId: work-testing
  • version: 2.8.0-alpha02

Artifact androidx.work:work-testing:2.8.0-alpha02 it located at Google repository (https://maven.google.com/)

Overview

Additional functionality exposed for WorkManager that are useful in the context of testing.

Summary

Methods
public voidsetAllConstraintsMet(java.util.UUID workSpecId)

Tells TestDriver to pretend that all constraints on the WorkRequest with the given workSpecId are met.

public voidsetInitialDelayMet(java.util.UUID workSpecId)

Tells TestDriver to pretend that the initial delay the OneTimeWorkRequest with the given workSpecId is met.

public voidsetPeriodDelayMet(java.util.UUID workSpecId)

Tells TestDriver to pretend that the period delay on the PeriodicWorkRequest with the given workSpecId is met.

Methods

public void setAllConstraintsMet(java.util.UUID workSpecId)

Tells TestDriver to pretend that all constraints on the WorkRequest with the given workSpecId are met. This may trigger execution of the work.

Parameters:

workSpecId: The WorkRequest's id

public void setInitialDelayMet(java.util.UUID workSpecId)

Tells TestDriver to pretend that the initial delay the OneTimeWorkRequest with the given workSpecId is met. This may trigger execution of the work.

Parameters:

workSpecId: The OneTimeWorkRequest's id

public void setPeriodDelayMet(java.util.UUID workSpecId)

Tells TestDriver to pretend that the period delay on the PeriodicWorkRequest with the given workSpecId is met. This may trigger execution of the work.

Parameters:

workSpecId: The PeriodicWorkRequest's id

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.work.testing;

import androidx.annotation.NonNull;

import java.util.UUID;

/**
 * Additional functionality exposed for {@link androidx.work.WorkManager} that are useful in the
 * context of testing.
 */
public interface TestDriver {

    /**
     * Tells {@link TestDriver} to pretend that all constraints on the
     * {@link androidx.work.WorkRequest} with the given {@code workSpecId} are met.  This may
     * trigger execution of the work.
     *
     * @param workSpecId The {@link androidx.work.WorkRequest}'s id
     * @throws IllegalArgumentException if {@code workSpecId} is not enqueued
     */
    void setAllConstraintsMet(@NonNull UUID workSpecId);

    /**
     * Tells {@link TestDriver} to pretend that the initial delay the
     * {@link androidx.work.OneTimeWorkRequest} with the given {@code workSpecId} is met.  This may
     * trigger execution of the work.
     *
     * @param workSpecId The {@link androidx.work.OneTimeWorkRequest}'s id
     * @throws IllegalArgumentException if {@code workSpecId} is not enqueued
     */
    void setInitialDelayMet(@NonNull UUID workSpecId);

    /**
     * Tells {@link TestDriver} to pretend that the period delay on the
     * {@link androidx.work.PeriodicWorkRequest} with the given {@code workSpecId} is met.  This may
     * trigger execution of the work.
     *
     * @param workSpecId The {@link androidx.work.PeriodicWorkRequest}'s id
     * @throws IllegalArgumentException if {@code workSpecId} is not enqueued
     */
    void setPeriodDelayMet(@NonNull UUID workSpecId);
}