Alon
Alon

Reputation: 973

Android Espresso UI tests for custom views

I have created my own custom view which I use in one of my layouts. The class draws a canvas with the following parameters (see below). Is it possible to test my custom view using Android's Espresso UI tests?

The custom view class:

public class DialBrightness extends View {
    private static final int STROKE_WIDTH_DP = 1;
    private static final int DEFAULT_NUM_RAYS = 8;
    private int mMax;
    private int mMin;
    private int mValue;
    private Paint mInactivePaint;
    private Paint mActivePaint;
    private int mRayGap = 4;
    private boolean showBorder = false;

The xml layout:

<com.myapp.ui.view.DialBrightness
            android:id="@+id/dial_brightness"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            app:brightness_active_color="@color/accent"
            app:brightness_inactive_color="@color/xlight_gray"
            app:brightness_stroke_width_active="@dimen/aware_active_stroke"
            app:brightness_stroke_width_inactive="@dimen/aware_active_stroke"
            app:brightness_min="0"
            app:brightness_max="4"
            app:brightness_default="2"
            app:brightness_border="true"
            android:layout_gravity="center"/>

Upvotes: 2

Views: 1829

Answers (1)

Emmaaa
Emmaaa

Reputation: 320

What do you want to test about it? Yes there are some things that you can test using Espresso... For example, if you just wanted to check if it's present, you'd do:

onView(withId(R.id.dial_brightness)).check(matches(isDisplayed());

Check out the cheat sheet, that will give you an idea of the sorts of things that you can test using Espresso. https://developer.android.com/training/testing/espresso/cheat-sheet.html

Upvotes: 1

Related Questions