Coder Social home page Coder Social logo

mytestedapp's Introduction

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

mytestedapp's People

Contributors

kyle-ilantzis avatar

Watchers

James Cloos avatar P Campbell avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.