Espresso Testing check if string value of TextView in Listview does not exist

1.6k views Asked by At

I have a ListView that contains an ArrayList. Food.class contains String values like eg FoodName. Now I want to check if after deletion of a row from the ListView the Value FoodName does not exist at the specific position anymore. I tried following code which does not work:

onData(anything())
            .inAdapterView(withId(R.id.list))
            .atPosition(0)
            .onChildView(withId(R.id.food_name))
            .check("I don't know how to check if string value of food_name which I deleted before does not exist here anymore")

Thanks for help!

1

There are 1 answers

4
crgarridos On BEST ANSWER

You can do:

onData(anything())
            .inAdapterView(withId(R.id.list))
            .atPosition(0)
            .onChildView(withId(R.id.food_name))
            .check(matches(not(withText("Your old text"))));

or

onData(anything())
            .inAdapterView(withId(R.id.list))
            .atPosition(0)
            .check(matches(not(hasDescendant(withText("Your old text")))));

PS. I look to the expresso cheatsheet and is very useful when I face this kind of questions.