Skip to content

kyle-ilantzis/MyTestedApp

Repository files navigation

Android UI testing with espresso and mockito

This android application demonstrates android UI testing.

It has 2 screens:

  • the login screen
  • the profile page

Testing

Write integration tests for your application and its use cases.

Integration testing
... software modules are combined and tested as a group

https://en.wikipedia.org/wiki/Integration_testing

To achieve the most combined software modules tested together write UI tests with Espresso.

This allows you to test if you properly handle button clicks and text inputs. This allows you to test if your business rules are respected. This allows you to test various network errors (timeouts, server errors, client errors)

You should not test by hand when you can write code to do it for you. Not only for you but for the next developer that maintains your app.

Writing tests

In app/src/androidTest you find:

  • Tests for each activity
  • Robots to abstract tests and make them look more like english

Espresso is for integration tests. When using espresso all the code should be abstracted by a robot. See the following links for an idea on how to use espresso.

Mockito is for mocking the REST API. When mocking, all the code should be abstracted by InjectionRobot in app/src/androidTest. See the following links for an idea on how to use mockito.

Robots

Robots make the tests look more human readable. They allow tests to say the WHAT. The robot implementation says the HOW (and the how is ugly espresso functions and ugly mocking details).

For more information see Instrumentation Testing Robots by Jake Wharton.

Run the tests

In Android Studio right click on app/src/androidTest/java and choose "Run All Tests"

Run the app

Start the server

Assuming you have nodejs and npm installed

$> cd server
$> npm install
$> ./start

Start the app

In android studio install the app on an emulator.

If you want to run the app on a device you will need to change the IP address of the server. In Injection.java change the provideRestService method. Change the baseUrl to your machine's IP address.

References

About

android UI testing with espresso and mockito

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published