Stay organized with collections
Save and categorize content based on your preferences.
ViewAssertion
public
interface
ViewAssertion
android.support.test.espresso.ViewAssertion
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.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# ViewAssertion\n=============\n\n| This package is part of the Android [support library](/topic/libraries/support-library) which is no longer maintained. The support library has been superseded by [AndroidX](/jetpack/androidx) which is part of [Jetpack](/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider [migrating](/jetpack/androidx/migrate) existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library [class\n| mappings](/jetpack/androidx/migrate/class-mappings).\n\n\n`\npublic\n\n\ninterface\nViewAssertion\n`\n\n\n`\n\n\n`\n\n|---------------------------------------------|\n| android.support.test.espresso.ViewAssertion |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nResponsible for performing assertions on a View element. \n\n\nThis is considered part of the test framework public API - developers are free to write their\nown assertions as long as they meet the following requirements:\n\n- Do not mutate the passed in view.\n- Throw junit.framework.AssertionError when the view assertion does not hold.\n- Implementation runs on the UI thread - so it should not do any blocking operations\n- 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.\n- It is encouraged to access non-mutating methods on the view to perform assertion.\n\n\u003cbr /\u003e\n\nStrongly consider using a existing ViewAssertion via the ViewAssertions utility class before\nwriting your own assertion.\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[check](/reference/android/support/test/espresso/ViewAssertion#check(android.view.View, android.support.test.espresso.NoMatchingViewException))`(`[View](https://developer.android.com/reference/android/view/View.html)` view, `[NoMatchingViewException](/reference/android/support/test/espresso/NoMatchingViewException)` noViewFoundException) ` Checks the state of the given view (if such a view is present). |\n\nPublic methods\n--------------\n\n### check\n\n```\nvoid check (View view, \n NoMatchingViewException noViewFoundException)\n```\n\nChecks the state of the given view (if such a view is present).\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|\n| `view` | `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) \u003cbr /\u003e |\n| `noViewFoundException` | `NoMatchingViewException`: an exception detailing why the view could not be found or null if the view was found \u003cbr /\u003e |\n\n-\n\n Interfaces\n ----------\n\n - [EspressoException](/reference/android/support/test/espresso/EspressoException)\n - [FailureHandler](/reference/android/support/test/espresso/FailureHandler)\n - [IdlingResource](/reference/android/support/test/espresso/IdlingResource)\n - [IdlingResource.ResourceCallback](/reference/android/support/test/espresso/IdlingResource.ResourceCallback)\n - [UiController](/reference/android/support/test/espresso/UiController)\n - [ViewAction](/reference/android/support/test/espresso/ViewAction)\n - [ViewAssertion](/reference/android/support/test/espresso/ViewAssertion)\n - [ViewFinder](/reference/android/support/test/espresso/ViewFinder)\n - [ViewInteractionComponent](/reference/android/support/test/espresso/ViewInteractionComponent)\n-\n\n Classes\n -------\n\n - [AmbiguousViewMatcherException.Builder](/reference/android/support/test/espresso/AmbiguousViewMatcherException.Builder)\n - [DataInteraction](/reference/android/support/test/espresso/DataInteraction)\n - [DataInteraction.DisplayDataMatcher](/reference/android/support/test/espresso/DataInteraction.DisplayDataMatcher)\n - [Espresso](/reference/android/support/test/espresso/Espresso)\n - [IdlingPolicies](/reference/android/support/test/espresso/IdlingPolicies)\n - [IdlingPolicy](/reference/android/support/test/espresso/IdlingPolicy)\n - [IdlingRegistry](/reference/android/support/test/espresso/IdlingRegistry)\n - [NoMatchingViewException.Builder](/reference/android/support/test/espresso/NoMatchingViewException.Builder)\n - [PerformException.Builder](/reference/android/support/test/espresso/PerformException.Builder)\n - [Root](/reference/android/support/test/espresso/Root)\n - [Root.Builder](/reference/android/support/test/espresso/Root.Builder)\n - [ViewInteraction](/reference/android/support/test/espresso/ViewInteraction)\n-\n\n Exceptions\n ----------\n\n - [AmbiguousViewMatcherException](/reference/android/support/test/espresso/AmbiguousViewMatcherException)\n - [AppNotIdleException](/reference/android/support/test/espresso/AppNotIdleException)\n - [IdlingResourceTimeoutException](/reference/android/support/test/espresso/IdlingResourceTimeoutException)\n - [InjectEventSecurityException](/reference/android/support/test/espresso/InjectEventSecurityException)\n - [NoActivityResumedException](/reference/android/support/test/espresso/NoActivityResumedException)\n - [NoMatchingRootException](/reference/android/support/test/espresso/NoMatchingRootException)\n - [NoMatchingViewException](/reference/android/support/test/espresso/NoMatchingViewException)\n - [PerformException](/reference/android/support/test/espresso/PerformException)"]]