我创建了自己的自定义视图,我在其中一个布局中使用了该视图。该类使用以下参数绘制画布(参见下文)。是否可以使用Android的Espresso UI测试来测试我的自定义视图?
自定义视图类:
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;
xml布局:
<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"/>
答案 0 :(得分:1)
你想测试什么?是的,您可以使用Espresso测试一些东西...例如,如果您只想检查它是否存在,您可以这样做:
onView(withId(R.id.dial_brightness)).check(matches(isDisplayed));
查看备忘单,这将让您了解可以使用Espresso测试的各种事物。 sheethttps://developer.android.com/training/testing/espresso/cheat-sheet.html