Screenshot Kata for Android Developers. The main goal is to practice UI Testing.
Java
Latest commit 488b48a Dec 20, 2016 @pedrovgs pedrovgs Add Travis-CI badge
Permalink
Failed to load latest commit information.
app Prepare kata screenshot (#1) Dec 20, 2016
art Initial commit using KataSuperHeroesAndroid as example Dec 19, 2016
config Initial commit using KataSuperHeroesAndroid as example Dec 19, 2016
gradle/wrapper Initial commit using KataSuperHeroesAndroid as example Dec 19, 2016
.gitignore Prepare kata screenshot (#1) Dec 20, 2016
.travis.yml Prepare kata screenshot (#1) Dec 20, 2016
CONTRIBUTING.md Initial commit using KataSuperHeroesAndroid as example Dec 19, 2016
LICENSE.txt
README.md Add Travis-CI badge Dec 20, 2016
build.gradle Initial commit using KataSuperHeroesAndroid as example Dec 19, 2016
gradle.properties Initial commit using KataSuperHeroesAndroid as example Dec 19, 2016
gradlew Initial commit using KataSuperHeroesAndroid as example Dec 19, 2016
gradlew.bat Initial commit using KataSuperHeroesAndroid as example Dec 19, 2016
settings.gradle Initial commit using KataSuperHeroesAndroid as example Dec 19, 2016

README.md

Karumi logo KataScreenshot for Android. Build Status

You can compare this testing approach with a different testing strategy where the application UI is tested using just Espresso.


Getting started

This repository contains an Android application to show Super Heroes information:

ApplicationScreencast

This Application is based on two Activities:

  • MainActivity showing a list of super heroes with name, photo and a special badge if is part of the Avengers Team.

MainActivityScreenhot

  • SuperHeroDetailActivity showing detailed information about a super hero like his or her name, photo and description.

SuperHeroDetailActivityScreenshot

The application architecture, dependencies and configuration is ready to just start writing tests. In this project you'll find Dagger2 configured to be able to replace production code with test doubles easily and Espresso to be able to interact with the application user interface and a screenshot testing framework ready to compare your application changes.

Remember that after any production code change you can record your screenshots again executing:

./gradlew recordMode screenshotTests

To verify the correct behaviour of your code you can execute:

./gradlew verifyMode screenshotTests

To be able to get a deterministic test scenario all our tests will be executed on the same emulated device. You can use the Travis-CI configuration to get the same emulator working on your computer.

Tasks

Your task as Android Developer is to write all the UI tests needed to check if the Application UI is working as it should.

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

    1. Fork this repository.
    2. Checkout kata-screenshot branch.
    3. Execute the application, explore it manually and make yourself familiar with the code.
    4. Execute MainActivityTest and watch the only test it contains pass.
  • To help you get started, these are some test cases for MainActivity:

    1. Setup mocked SuperHeroesRepository in MainActivityTest to return a list of some Super Heroes.
    2. Test the MainActivity is showing the super heroes obtained from the SuperHeroesRepository.
    3. Test the empty case is shown if there are no super heroes.

Considerations

  • If you get stuck, Master branch contains already solved tests for MainActivity, SuperHeroDetailActivity and SuperHeroViewHolder.

  • 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.

Extra Tasks

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 MainActivity and test it.
  • Modify SuperHeroDetailActivity to 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 SnackBar to indicate something went wrong.
  • Modify SuperHeroesRepository test double to perform a Thread.sleep and use the custom idling resources you'll find in this repository to get your tests working.
  • Compare your tests implementation with the KataSuperHeroes solved using Espresso.

Documentation

There are some links which can be useful to finish these tasks:

Data provided by Marvel. © 2017 MARVEL

License

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.