Added in API level 1
Deprecated in API level 24

ViewAsserts

public class ViewAsserts
extends Object

java.lang.Object
   ↳ android.test.ViewAsserts


This class was deprecated in API level 24.
Use Espresso View Matchers instead. New test should be written using the Android Testing Support Library. For more information about UI testing, take the Espresso UI testing training.

Some useful assertions about views.

Summary

Public methods

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.

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.

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.

static void assertGroupContains(ViewGroup parent, View child)

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

static void assertGroupIntegrity(ViewGroup parent)

Assert the specified group's integrity.

static void assertGroupNotContains(ViewGroup parent, View child)

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

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.

static void assertHorizontalCenterAligned(View reference, View test)

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

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.

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.

static void assertOffScreenAbove(View origin, View view)

Assert that view is above the visible screen.

static void assertOffScreenBelow(View origin, View view)

Assert that view is below the visible screen.

static void assertOnScreen(View origin, View view)

Assert that view is on the screen.

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.

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.

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.

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.

static void assertVerticalCenterAligned(View reference, View test)

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

Inherited methods

Public methods

assertBaselineAligned

Added in API level 1
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.

Parameters
first View: The first view

second View: The second view

assertBottomAligned

Added in API level 1
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.

Parameters
first View: The first view

second View: The second view

margin int: The margin between the first view and the second view

assertBottomAligned

Added in API level 1
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.

Parameters
first View: The first view

second View: The second view

assertGroupContains

Added in API level 1
public static void assertGroupContains (ViewGroup parent, 
                View child)

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

Parameters
parent ViewGroup: The group

child View: The child that should belong to group

assertGroupIntegrity

Added in API level 1
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.

Parameters
parent ViewGroup: The group whose integrity to check

assertGroupNotContains

Added in API level 1
public static void assertGroupNotContains (ViewGroup parent, 
                View child)

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

Parameters
parent ViewGroup: The group

child View: The child that should not belong to group

assertHasScreenCoordinates

Added in API level 1
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.

Parameters
origin View: The root view of the screen.

view View: The view.

x int: The expected x coordinate.

y int: The expected y coordinate.

assertHorizontalCenterAligned

Added in API level 1
public static void assertHorizontalCenterAligned (View reference, 
                View test)

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

Parameters
reference View: The reference view

test View: The view that should be center aligned with the reference view

assertLeftAligned

Added in API level 1
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.

Parameters
first View: The first view

second View: The second view

assertLeftAligned

Added in API level 1
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.

Parameters
first View: The first view

second View: The second view

margin int: The margin between the first view and the second view

assertOffScreenAbove

Added in API level 1
public static void assertOffScreenAbove (View origin, 
                View view)

Assert that view is above the visible screen.

Parameters
origin View: Te root view of the screen.

view View: The view

assertOffScreenBelow

Added in API level 1
public static void assertOffScreenBelow (View origin, 
                View view)

Assert that view is below the visible screen.

Parameters
origin View: The root view of the screen.

view View: The view

assertOnScreen

Added in API level 1
public static void assertOnScreen (View origin, 
                View view)

Assert that view is on the screen.

Parameters
origin View: The root view of the screen.

view View: The view.

assertRightAligned

Added in API level 1
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.

Parameters
first View: The first view

second View: The second view

margin int: The margin between the first view and the second view

assertRightAligned

Added in API level 1
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.

Parameters
first View: The first view

second View: The second view

assertTopAligned

Added in API level 1
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.

Parameters
first View: The first view

second View: The second view

margin int: The margin between the first view and the second view

assertTopAligned

Added in API level 1
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.

Parameters
first View: The first view

second View: The second view

assertVerticalCenterAligned

Added in API level 1
public static void assertVerticalCenterAligned (View reference, 
                View test)

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

Parameters
reference View: The reference view

test View: The view that should be center aligned with the reference view