Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/android/test/ViewAsserts#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/test/ViewAsserts#inhmethods)

# ViewAsserts

*** ** * ** ***

` public class ViewAsserts `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.test.ViewAsserts |

<br />

*** ** * ** ***

<br />

**This class was deprecated in API level 24.**   

Use [Espresso View Matchers](https://developer.android.com/reference/android/support/test/espresso/matcher/ViewMatchers) instead. New test should be written using the [Android Testing Support Library](https://developer.android.com/tools/testing-support-library). For more information about UI testing, take the [Espresso UI testing](https://developer.android.com/tools/testing-support-library) training.

Some useful assertions about views.

## Summary

| ### Public methods ||
|---|---|
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertBaselineAligned(android.view.View,%20android.view.View)(https://developer.android.com/reference/android/view/View first, https://developer.android.com/reference/android/view/View second) ` Assert that two views are aligned on their baseline, that is that their baselines are on the same y location. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertBottomAligned(android.view.View,%20android.view.View,%20int)(https://developer.android.com/reference/android/view/View first, https://developer.android.com/reference/android/view/View second, int margin) ` Assert that two views are bottom aligned, that is that their bottom edges are on the same y location, with respect to the specified margin. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertBottomAligned(android.view.View,%20android.view.View)(https://developer.android.com/reference/android/view/View first, https://developer.android.com/reference/android/view/View second) ` Assert that two views are bottom aligned, that is that their bottom edges are on the same y location. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertGroupContains(android.view.ViewGroup,%20android.view.View)(https://developer.android.com/reference/android/view/ViewGroup parent, https://developer.android.com/reference/android/view/View child) ` Assert that the specified group contains a specific child once and only once. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertGroupIntegrity(android.view.ViewGroup)(https://developer.android.com/reference/android/view/ViewGroup parent) ` Assert the specified group's integrity. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertGroupNotContains(android.view.ViewGroup,%20android.view.View)(https://developer.android.com/reference/android/view/ViewGroup parent, https://developer.android.com/reference/android/view/View child) ` Assert that the specified group does not contain a specific child. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertHasScreenCoordinates(android.view.View,%20android.view.View,%20int,%20int)(https://developer.android.com/reference/android/view/View origin, https://developer.android.com/reference/android/view/View view, int x, int y) ` Assert that a view has a particular x and y position on the visible screen. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertHorizontalCenterAligned(android.view.View,%20android.view.View)(https://developer.android.com/reference/android/view/View reference, https://developer.android.com/reference/android/view/View test) ` Assert that the `test` view is horizontally center aligned with respect to the `reference` view. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertLeftAligned(android.view.View,%20android.view.View)(https://developer.android.com/reference/android/view/View first, https://developer.android.com/reference/android/view/View second) ` Assert that two views are left aligned, that is that their left edges are on the same x location. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertLeftAligned(android.view.View,%20android.view.View,%20int)(https://developer.android.com/reference/android/view/View first, https://developer.android.com/reference/android/view/View second, int margin) ` Assert that two views are left aligned, that is that their left edges are on the same x location, with respect to the specified margin. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertOffScreenAbove(android.view.View,%20android.view.View)(https://developer.android.com/reference/android/view/View origin, https://developer.android.com/reference/android/view/View view) ` Assert that view is above the visible screen. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertOffScreenBelow(android.view.View,%20android.view.View)(https://developer.android.com/reference/android/view/View origin, https://developer.android.com/reference/android/view/View view) ` Assert that view is below the visible screen. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertOnScreen(android.view.View,%20android.view.View)(https://developer.android.com/reference/android/view/View origin, https://developer.android.com/reference/android/view/View view) ` Assert that view is on the screen. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertRightAligned(android.view.View,%20android.view.View,%20int)(https://developer.android.com/reference/android/view/View first, https://developer.android.com/reference/android/view/View second, int margin) ` Assert that two views are right aligned, that is that their right edges are on the same x location, with respect to the specified margin. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertRightAligned(android.view.View,%20android.view.View)(https://developer.android.com/reference/android/view/View first, https://developer.android.com/reference/android/view/View second) ` Assert that two views are right aligned, that is that their right edges are on the same x location. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertTopAligned(android.view.View,%20android.view.View,%20int)(https://developer.android.com/reference/android/view/View first, https://developer.android.com/reference/android/view/View second, int margin) ` Assert that two views are top aligned, that is that their top edges are on the same y location, with respect to the specified margin. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertTopAligned(android.view.View,%20android.view.View)(https://developer.android.com/reference/android/view/View first, https://developer.android.com/reference/android/view/View second) ` Assert that two views are top aligned, that is that their top edges are on the same y location. |
| ` static void` | ` https://developer.android.com/reference/android/test/ViewAsserts#assertVerticalCenterAligned(android.view.View,%20android.view.View)(https://developer.android.com/reference/android/view/View reference, https://developer.android.com/reference/android/view/View test) ` Assert that the `test` view is vertically center aligned with respect to the `reference` view. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public methods

### assertBaselineAligned

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertBaselineAligned (View first, 
                View second)
```

Assert that two views are aligned on their baseline, that is that their baselines are on the same y location.

<br />

| Parameters ||
|---|---|
| `first` | `View`: The first view <br /> |
| `second` | `View`: The second view <br /> |

### assertBottomAligned

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertBottomAligned (View first, 
                View second, 
                int margin)
```

Assert that two views are bottom aligned, that is that their bottom edges are on the same y location, with respect to the specified margin.

<br />

| Parameters ||
|---|---|
| `first` | `View`: The first view <br /> |
| `second` | `View`: The second view <br /> |
| `margin` | `int`: The margin between the first view and the second view <br /> |

### assertBottomAligned

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertBottomAligned (View first, 
                View second)
```

Assert that two views are bottom aligned, that is that their bottom edges are on the same y location.

<br />

| Parameters ||
|---|---|
| `first` | `View`: The first view <br /> |
| `second` | `View`: The second view <br /> |

### assertGroupContains

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertGroupContains (ViewGroup parent, 
                View child)
```

Assert that the specified group contains a specific child once and only once.

<br />

| Parameters ||
|---|---|
| `parent` | `ViewGroup`: The group <br /> |
| `child` | `View`: The child that should belong to group <br /> |

### assertGroupIntegrity

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertGroupIntegrity (ViewGroup parent)
```

Assert the specified group's integrity. The children count should be \>= 0 and each child should be non-null.

<br />

| Parameters ||
|---|---|
| `parent` | `ViewGroup`: The group whose integrity to check <br /> |

### assertGroupNotContains

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertGroupNotContains (ViewGroup parent, 
                View child)
```

Assert that the specified group does not contain a specific child.

<br />

| Parameters ||
|---|---|
| `parent` | `ViewGroup`: The group <br /> |
| `child` | `View`: The child that should not belong to group <br /> |

### assertHasScreenCoordinates

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertHasScreenCoordinates (View origin, 
                View view, 
                int x, 
                int y)
```

Assert that a view has a particular x and y position on the visible screen.

<br />

| Parameters ||
|---|---|
| `origin` | `View`: The root view of the screen. <br /> |
| `view` | `View`: The view. <br /> |
| `x` | `int`: The expected x coordinate. <br /> |
| `y` | `int`: The expected y coordinate. <br /> |

### assertHorizontalCenterAligned

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertHorizontalCenterAligned (View reference, 
                View test)
```

Assert that the `test` view is horizontally center aligned with respect to the `reference` view.

<br />

| Parameters ||
|---|---|
| `reference` | `View`: The reference view <br /> |
| `test` | `View`: The view that should be center aligned with the reference view <br /> |

### assertLeftAligned

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertLeftAligned (View first, 
                View second)
```

Assert that two views are left aligned, that is that their left edges are on the same x location.

<br />

| Parameters ||
|---|---|
| `first` | `View`: The first view <br /> |
| `second` | `View`: The second view <br /> |

### assertLeftAligned

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertLeftAligned (View first, 
                View second, 
                int margin)
```

Assert that two views are left aligned, that is that their left edges are on the same x location, with respect to the specified margin.

<br />

| Parameters ||
|---|---|
| `first` | `View`: The first view <br /> |
| `second` | `View`: The second view <br /> |
| `margin` | `int`: The margin between the first view and the second view <br /> |

### assertOffScreenAbove

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertOffScreenAbove (View origin, 
                View view)
```

Assert that view is above the visible screen.

<br />

| Parameters ||
|---|---|
| `origin` | `View`: Te root view of the screen. <br /> |
| `view` | `View`: The view <br /> |

### assertOffScreenBelow

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertOffScreenBelow (View origin, 
                View view)
```

Assert that view is below the visible screen.

<br />

| Parameters ||
|---|---|
| `origin` | `View`: The root view of the screen. <br /> |
| `view` | `View`: The view <br /> |

### assertOnScreen

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertOnScreen (View origin, 
                View view)
```

Assert that view is on the screen.

<br />

| Parameters ||
|---|---|
| `origin` | `View`: The root view of the screen. <br /> |
| `view` | `View`: The view. <br /> |

### assertRightAligned

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertRightAligned (View first, 
                View second, 
                int margin)
```

Assert that two views are right aligned, that is that their right edges are on the same x location, with respect to the specified margin.

<br />

| Parameters ||
|---|---|
| `first` | `View`: The first view <br /> |
| `second` | `View`: The second view <br /> |
| `margin` | `int`: The margin between the first view and the second view <br /> |

### assertRightAligned

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertRightAligned (View first, 
                View second)
```

Assert that two views are right aligned, that is that their right edges are on the same x location.

<br />

| Parameters ||
|---|---|
| `first` | `View`: The first view <br /> |
| `second` | `View`: The second view <br /> |

### assertTopAligned

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertTopAligned (View first, 
                View second, 
                int margin)
```

Assert that two views are top aligned, that is that their top edges are on the same y location, with respect to the specified margin.

<br />

| Parameters ||
|---|---|
| `first` | `View`: The first view <br /> |
| `second` | `View`: The second view <br /> |
| `margin` | `int`: The margin between the first view and the second view <br /> |

### assertTopAligned

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertTopAligned (View first, 
                View second)
```

Assert that two views are top aligned, that is that their top edges are on the same y location.

<br />

| Parameters ||
|---|---|
| `first` | `View`: The first view <br /> |
| `second` | `View`: The second view <br /> |

### assertVerticalCenterAligned

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void assertVerticalCenterAligned (View reference, 
                View test)
```

Assert that the `test` view is vertically center aligned with respect to the `reference` view.

<br />

| Parameters ||
|---|---|
| `reference` | `View`: The reference view <br /> |
| `test` | `View`: The view that should be center aligned with the reference view <br /> |