Skip to content

Commit b7e0492

Browse files
committed
make test negative
1 parent 5e0e1b2 commit b7e0492

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

  • ui/espresso/RecyclerViewSample/app/src/androidTest/java/com/example/android/testing/espresso/RecyclerViewSample

ui/espresso/RecyclerViewSample/app/src/androidTest/java/com/example/android/testing/espresso/RecyclerViewSample/RecyclerViewSampleTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
import static androidx.test.espresso.Espresso.onView;
2121
import static androidx.test.espresso.action.ViewActions.click;
2222
import static androidx.test.espresso.assertion.ViewAssertions.matches;
23+
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
2324
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
2425
import static androidx.test.espresso.matcher.ViewMatchers.withText;
2526

2627
import androidx.test.core.app.ActivityScenario;
2728
import androidx.test.espresso.contrib.RecyclerViewActions;
2829
import androidx.test.espresso.matcher.ViewMatchers;
30+
import androidx.test.espresso.PerformException;
2931
import androidx.test.ext.junit.rules.ActivityScenarioRule;
3032
import androidx.test.filters.LargeTest;
3133
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -55,16 +57,14 @@ public class RecyclerViewSampleTest {
5557
@Rule
5658
public ActivityScenarioRule<MainActivity> activityScenarioRule =
5759
new ActivityScenarioRule<MainActivity>(MainActivity.class);
58-
59-
@Test
60-
public void itemWithText_exists() {
61-
String itemElementText = activityRule.getActivity().getResources()
62-
.getString(R.string.item_element_text);
6360

64-
// scrollTo will fail if no item matches.
61+
@Test(expected = PerformException.class)
62+
public void itemWithText_doesNotExist() {
63+
// Attempt to scroll to an item that contains the special text.
6564
onView(ViewMatchers.withId(R.id.recyclerView))
65+
// scrollTo will fail the test if no item matches.
6666
.perform(RecyclerViewActions.scrollTo(
67-
hasDescendant(withText(itemElementText))
67+
hasDescendant(withText("not in the list"))
6868
));
6969
}
7070

0 commit comments

Comments
 (0)