# ViewAssertion

# ViewAssertion

Artifact:[androidx.test.espresso:espresso-core](https://developer.android.com/jetpack/androidx/releases/test-espresso)  
[View Source](https://cs.android.com/search?q=file:androidx/test/espresso/ViewAssertion.java+class:androidx.test.espresso.ViewAssertion)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/test/espresso/ViewAssertion "View this page in Java")

<br />

```
interface ViewAssertion
```

<br />

*** ** * ** ***

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

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [check](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAssertion#check(android.view.View,androidx.test.espresso.NoMatchingViewException))`(view: `[View](https://developer.android.com/reference/android/view/View.html)`!, noViewFoundException: `[NoMatchingViewException](https://developer.android.com/reference/kotlin/androidx/test/espresso/NoMatchingViewException)`!)` Checks the state of the given view (if such a view is present). |

## Public functions

### check

```
fun check(view: View!, noViewFoundException: NoMatchingViewException!): Unit
```

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

|                                                                     Parameters                                                                      |
|-----------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|
| `view: `[View](https://developer.android.com/reference/android/view/View.html)`!`                                                                   | 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: `[NoMatchingViewException](https://developer.android.com/reference/kotlin/androidx/test/espresso/NoMatchingViewException)`!` | an exception detailing why the view could not be found or null if the view was found                                              |