- We are here to practice UI Testing.
- We are going to use Espresso to interact with the Application UI.
- We are going to use Kodein to replace production code with Test Doubles.
- We are going to practice pair programming.
This repository contains an Android application to show Super Heroes information:
This Application is based on two Activities:
MainActivityshowing a list of super heroes with name, photo and a special badge if is part of the Avengers Team.
SuperHeroDetailActivityshowing detailed information about a super hero like his or her name, photo and description.
The application architecture, dependencies and configuration is ready to just start writing tests. In this project you'll find Kodein configured to be able to replace production code with test doubles easily and Espresso to be able to interact with the application user interface.
Your task as Android Developer is to write all the UI tests needed to check if the Application UI is working as expected.
This repository is ready to build the application, pass the checkstyle and your tests in Travis-CI environments.
Our recommendation for this exercise is:
-
Before starting
- Fork this repository.
- Checkout
kata-super-heroesbranch. - Execute the application, explore it manually and make yourself familiar with the code.
- Execute
MainActivityTestand watch the only test it contains pass.
-
To help you get started, these are some test cases for
MainActivity:- Setup mocked
SuperHeroRepositoryinMainActivityTestto return a list of some Super Heroes. - Test that RecyclerView is listing the correct number of elements when
SuperHeroesRepositoryreturns a list of some Super Heroes. - Test that each of this elements contains the correct Super Hero name.
- Setup mocked
-
If you get stuck,
masterbranch contains already solved tests forMainActivityandSuperHeroDetailActivity -
You will find some utilities to help you test RecyclerViews and Toolbars easily in:
app/src/androidTest/java/com/karumi/matchersandapp/src/androidTest/java/com/karumi/recyclerview.-
RecyclerViewInteraction: provides an easy way to apply an Espresso matcher to all of the RecyclerView elementsRecyclerViewInteraction.onRecyclerView<ITEM_TYPE>(withId(R.id.recycler_view)) .withItems(A_LIST_OF_ITEMS) .check({ item, view, 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.
-
If you've covered all the application functionality using UI tests try to continue with the following tasks:
- Add a pull to refresh mechanism to
MainActivityand test it. - Modify
SuperHeroDetailActivityto handle an error case where the name of the super hero used to start this activity does not exist and show a message if this happens. - Modify the project to handle connection errors and show a
SnackBarto indicate something went wrong. - Modify
SuperHeroesRepositorytest double to perform aThread.sleepand use the custom idling resources you'll find in this repository to get your tests working.
There are some links which can be useful to finish these tasks:
- SuperHeroes Kata in Java
- Android Testing Support Library official documentation
- Espresso Cheat Sheet
- Espresso Idling Resources
- Espresso Custom Matchers
- Finding UI views
- Espresso Test Toolbar Title
Data provided by Marvel. © 2017 MARVEL
Copyright 2017 Karumi
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.