Skip to content
David González edited this page Jul 31, 2016 · 1 revision

Considerations

  • If you get stuck, Master branch contains already solved tests for SuperHeroesLoginActivity, SuperHeroesActivityTest and SuperHeroDetailActivity

  • A DaggerMockRule is an utility to let you create Dagger 2 modules dynamically. In this case we are using it to create a new MainModule in this testing scope. Instead of returning real objects, this new MainModule will returns the mock for SuperHeroesRepository defined in this test.

  • You will find some utilities to help you test RecyclerViews and Toolbars easily in: app/src/androidTest/java/com/karumi/katasuperheroes/matchers and app/src/androidTest/java/com/karumi/katasuperheroes/recyclerview.

    • RecyclerViewInteraction: provides an easy way to apply an Espresso matcher to all of the RecyclerView elements

      RecyclerViewInteraction.<ITEM_TYPE>onRecyclerView(withId(R.id.recycler_view))
      .withItems(A_LIST_OF_ITEMS)
      .check(new RecyclerViewInteraction.ItemViewAssertion<ITEM_TYPE>() {
          @Override
          public void check(ITEM_TYPE item, View view, NoMatchingViewException e) {
              matches(A_MATCHER).check(view, e);
          }
      });
    • RecyclerViewItemsCountMatcher: a matcher that returns true if RecyclerView contains the expected number of elements.

    • ToolbarMatcher: a matcher that returns true if a Toolbar with expected title is found.

Clone this wiki locally