public interface

ViewAssertion

 androidx.test.espresso.ViewAssertion

Gradle dependencies

compile group: 'androidx.test.espresso', name: 'espresso-core', version: '3.5.0-alpha06'

  • groupId: androidx.test.espresso
  • artifactId: espresso-core
  • version: 3.5.0-alpha06

Artifact androidx.test.espresso:espresso-core:3.5.0-alpha06 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test.espresso:espresso-core com.android.support.test.espresso:espresso-core

Androidx class mapping:

androidx.test.espresso.ViewAssertion android.support.test.espresso.ViewAssertion

Overview

Responsible for performing assertions on a View element.

This is considered part of the test framework public API - developers are free to write their own assertions as long as they meet the following requirements:

  • Do not mutate the passed in view.
  • Throw junit.framework.AssertionError when the view assertion does not hold.
  • Implementation runs on the UI thread - so it should not do any blocking operations
  • Downcasting the view to a specific type is allowed, provided there is a test that view is an instance of that type before downcasting. If not, an AssertionError should be thrown.
  • It is encouraged to access non-mutating methods on the view to perform assertion.

Strongly consider using a existing ViewAssertion via the ViewAssertions utility class before writing your own assertion.

Summary

Methods
public voidcheck(View view, NoMatchingViewException noViewFoundException)

Checks the state of the given view (if such a view is present).

Methods

public void check(View view, NoMatchingViewException noViewFoundException)

Checks the state of the given view (if such a view is present).

Parameters:

view: the view, if one was found during the view interaction or null if it was not (which may be an acceptable option for an assertion)
noViewFoundException: an exception detailing why the view could not be found or null if the view was found

Source

/*
 * Copyright (C) 2014 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.test.espresso;

import android.view.View;

/**
 * Responsible for performing assertions on a View element.<br>
 *
 * <p>This is considered part of the test framework public API - developers are free to write their
 * own assertions as long as they meet the following requirements:
 *
 * <ul>
 *   <li>Do not mutate the passed in view.
 *   <li>Throw junit.framework.AssertionError when the view assertion does not hold.
 *   <li>Implementation runs on the UI thread - so it should not do any blocking operations
 *   <li>Downcasting the view to a specific type is allowed, provided there is a test that view is
 *       an instance of that type before downcasting. If not, an AssertionError should be thrown.
 *   <li>It is encouraged to access non-mutating methods on the view to perform assertion.
 * </ul>
 *
 * <br>
 *
 * <p>Strongly consider using a existing ViewAssertion via the ViewAssertions utility class before
 * writing your own assertion.
 */
public interface ViewAssertion {

  /**
   * Checks the state of the given view (if such a view is present).
   *
   * @param view the view, if one was found during the view interaction or null if it was not (which
   *     may be an acceptable option for an assertion)
   * @param noViewFoundException an exception detailing why the view could not be found or null if
   *     the view was found
   */
  void check(View view, NoMatchingViewException noViewFoundException);
}