LoginSignup
0
0

More than 5 years have passed since last update.

EspressoでSpinnerの選択肢に特定の文字列が存在しない事をテストしたい

Posted at

標準版に存在する選択肢が特定のproductFlavorでのみ存在しない事をテストしたい、という状況がありましたが、あまりいい方法が思い浮かばなかったのでかなりいい加減で酷いコードです。

onDataでマッチするものがなかった場合、performやcheckを読んだ時点でRuntimeExceptionを吐く事を利用しています。

// 例:標準版には選択肢1・選択肢2・選択肢3が存在するが、テスト対象には選択肢1と選択肢2しか存在してはいけない事のテスト
onView(withId(R.id.spinner)).perform(click());
onData(allOf(is(instanceOf(String.class)), is("選択肢1"))).check(matches(notNullValue()));
onData(allOf(is(instanceOf(String.class)), is("選択肢2"))).check(matches(notNullValue()));
try {
    onData(allOf(is(instanceOf(String.class)), is("選択肢3"))).check(matches(notNullValue()));
    fail("選択肢3が存在する");
} catch (RuntimeException ignored) {

}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0