O'Reilly logo

Mastering Android Studio 3 by Kyle Mew

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing lists and data

The preceding example uses onView() to identify the views we want to test using their ID, and this is fine for components we have already named; however, items in lists cannot be identified so explicitly, and, for this, we will need another approach. When dealing with lists, such as recycler views and spinners, Espresso provides the onData() method to identify list items.

To see this in action, add a spinner as shown in the following one of your app activities:

public class SomeActivity extends AppCompatActivity { ArrayList<String> levelList = new ArrayList<String>(); TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { . . . Spinner spinner = (Spinner) findViewById(R.id.spinner); levelList.add("Easy"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required